orthdonticModule.directive("orthdonticSelectAddStepView", [function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/components/orthdontic-select-add-step/orthdontic-select-add-step-view.html",
        scope: {
            visible: "=",
            stepList: "=",
            onSure: "&",
            onCancel: "&"
        },
        link: function(n) {
            var t = function(t) {
                    n.list = _.filter(n.stepList, function(n) {
                        return n.name.indexOf(t) > -1
                    })
                },
                i = function(t, i) {
                    t.stopPropagation();
                    n.selectItem = i
                },
                r = function(t) {
                    if (t.stopPropagation(), n.onSure) n.onSure({
                        selectItem: n.selectItem,
                        event: t
                    })
                },
                u = function(t) {
                    t.stopPropagation();
                    n.onCancel && n.onCancel()
                };
            n.$watch("stepList", function(t) {
                    n.list = t ? t : []
                }),
                function() {
                    n.onSearch = t;
                    n.sureStep = r;
                    n.cancelStep = u;
                    n.onSelectStepItem = i;
                    n.selectItem = null;
                    n.searchKey = ""
                }()
        }
    }
}]);
orthdonticModule.controller("OrthdonticEditTemplateChoiceCtrl", ["$log", "$scope", "$location", "$http", "$modalInstance", "aresDialog", "$state", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "aresNotification", "host", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    var k = p.treeControl,
        d = k.getTree(),
        g = p.isEmrCustomTemplateEnabled,
        nt = p.currentMedicalRecord,
        w, b;
    t.treeData = d;
    t.predicate = "";
    t.comparator = !1;
    t.opts = {
        showActionBar: !1
    };
    w = function() {
        u.dismiss("cancel")
    };
    b = function() {
            var n = t.currentEmrTemplate,
                i, r, f;
            t.currentMedicalRecord.oralCheckRecordList && (i = t.currentMedicalRecord.oralCheckRecordList.length - 1, i > -1 && (t.currentMedicalRecord.oralCheckRecordList[i].description = n.oralCheck));
            t.currentMedicalRecord.cureRecordList && (r = t.currentMedicalRecord.cureRecordList.length - 1, r > -1 && (t.currentMedicalRecord.cureRecordList[r].cure = n.treatment));
            t.currentMedicalRecord.treatmentAdviceList && (f = t.currentMedicalRecord.treatmentAdviceList.length - 1, f > -1 && (t.currentMedicalRecord.treatmentAdviceList[f].content = n.advice));
            u.close(t.currentMedicalRecord)
        },
        function() {
            t.closeTemplateData = w;
            t.saveTemplateData = b;
            t.currentMedicalRecord = nt;
            t.isEmrCustomTemplateEnabled = g
        }()
}]);
orthdonticModule.controller("OrthdonticExaminationCtrl", ["$scope", "$timeout", "$state", "$q", "$log", "$filter", "$modal", "$stateParams", "orthoSvc", "dataDicSvc", "patientSvc", "appointmentSvc", "constants", "imagingSvc", "enums", "patientDocumentSvc", "loginContext", "aresDialog", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b) {
    "use strict";

    function ot(n, t) {
        return n.position - t.position
    }

    function rt() {
        var t = {
                patientId: n.patientId,
                endTime: moment(Ares.today()).add(1, "d").format(a.dateFormat),
                cancel: !1,
                isPending: !1
            },
            i = h.officeDic.data();
        angular.forEach(n.examImages, function(n) {
            n.type = "preview"
        });
        l.searchAppointmentsByTenant(t).success(function(t) {
            var i, u, r;
            for (n.appointmentsList = t, i = 0; i < n.appointmentsList.length; ++i) u = lt(n.appointmentsList[i].officeId), n.appointmentsList[i].appointmentDescription = ct(n.appointmentsList[i].startTime) + " " + u, n.examImages.length > 0 && (r = _.filter(n.examImages, function(t) {
                return t.appointmentId === n.appointmentsList[i].id
            }), n.appointmentsList[i].previewImageList = r, n.appointmentsList[i].allImageList = r)
        })
    }

    function bi() {
        k = e.open({
            animation: !0,
            backdrop: "static",
            template: "<image-upload-view><\/image-upload-view>",
            controller: "ImageUploadlCtrl",
            windowClass: ".image-upload-dialog",
            size: "lg",
            resolve: {
                host: function() {
                    return {
                        imageUploadDialog: k
                    }
                }
            }
        });
        setTimeout(function() {
            $(".close").hide()
        }, 200)
    }

    function ht(t) {
        var r, i;
        if (n.appointmentsList) {
            for (r = [], i = 0; i < n.appointmentsList.length; ++i) n.appointmentsList[i].isCancelled || r.push(n.appointmentsList[i]);
            ft = e.open({
                animation: !0,
                backdrop: "static",
                template: "<image-select-appointment><\/image-select-appointment>",
                controller: "ImageAppointmentsCtrl",
                windowClass: "image-appointments-select-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            appointmentsList: r,
                            callback: ei,
                            patient: n.patient,
                            categoryType: n.categoryType,
                            usedFor: "orth",
                            image: t
                        }
                    }
                }
            })
        }
    }
    var ct = f("toDateTimeString"),
        gi = f("toFirstVisit"),
        lt = f("toOfficeAbbr"),
        k = null,
        ft = null,
        g = 0,
        d = 0;
    n.currentImageList;
    n.progressBarPercentage = "0%";
    n.allImageList;
    n.categoryType = null;
    n.fieldIdList = [];
    n.rootList = [];
    var at = 150 / 97.5,
        vt = 120 / 154,
        yt = function() {
            s.getPatientExamFields(n.patientId).success(function(t) {
                n.patientExamFields = t;
                h.orthoExamineFieldDic.load().then(function(t) {
                    if (t) {
                        var i = angular.copy(t);
                        i && i.length > 0 && (i[0].active = !0, i[0]._hasLoad = !0);
                        wt(i);
                        n.fields = i
                    }
                })
            })
        },
        et = function(t) {
            var i = _.find(n.patientExamFields, function(n) {
                    return n.fieldId === t.id
                }),
                r;
            return t.defaultValue ? i && (i.defaultValue = t.defaultValue) : (r = t.value, i && r && (i.defaultValue = r.split("|"))), i
        },
        pt = function(n) {
            if (n) {
                var t = null;
                n.name === "面部" ? t = {
                    id: 0,
                    name: "面部影像上传",
                    parentId: n.id,
                    _isChecked: !0,
                    _readOnly: !0
                } : n.name === "牙列" && (t = {
                    id: 0,
                    name: "牙列影像上传",
                    parentId: n.id,
                    _isChecked: !0,
                    _readOnly: !0
                });
                t && n.orthoFields.unshift(t)
            }
        },
        wt = function(t) {
            var r = [],
                u, i, f;
            if (_.forEach(t, function(n) {
                    var t = nt(n);
                    t && (t._isEditMode = !1, r.push(t))
                }), n.patientExamFields) {
                for (u = [], i = n.patientExamFields.length - 1; i >= 0; i--) f = n.patientExamFields[i].fieldId, u.push(f), n.rootList.push(n.patientExamFields[i].rootParentId), n.patientExamFields[i].field != null && (f = n.patientExamFields[i].field.parentId, u.push(f));
                n.fieldIdList = u
            }
            r && _.forEach(r, function(t) {
                var i = _.find(n.rootList, function(n) {
                    return n === t.id
                });
                t._isEditMode = !i;
                pt(t);
                _.forEach(t.orthoFields, function(t) {
                    if (i) {
                        var r = _.find(n.fieldIdList, function(n) {
                            return n === t.id
                        });
                        t._isChecked = t.name === "面部影像上传" || t.name === "牙列影像上传" ? !0 : r !== null && r !== undefined
                    } else t._isChecked = !0
                });
                t._isAllChecked = !_.filter(t.orthoFields, function(n) {
                    return !n._isChecked
                }).length > 0;
                t._isNotEmpty = _.any(t.orthoFields, function(n) {
                    return n._isChecked
                })
            });
            n.patientNewExamFields = r;
            n.examFieldCache = angular.copy(r);
            n.isDisableBtn = ut()
        },
        nt = function(n) {
            return _.forEach(n.orthoFields, function(n) {
                var t = et(n);
                t && t.value && (n.defaultValue = t.defaultValue, n.value = t.value, n.examFieldId = t.id);
                n.orthoFields && _.forEach(n.orthoFields, function(n) {
                    t = et(n);
                    t && t.value ? (n.defaultValue = t.defaultValue, n.value = t.value, n.examFieldId = t.id) : n.value && (n.defaultValue = n.value.split("|"), n.value = "")
                })
            }), n
        },
        bt = function(t) {
            _.forEach(n.patientNewExamFields, function(n) {
                t === n.id && (n.active = !n.active);
                n._hasLoad || (n._hasLoad = !0)
            })
        },
        kt = function(t, i) {
            n.examFieldCache[i] = angular.copy(t);
            t._isEditMode = !0;
            n.isDisableBtn = !0;
            tt(t)
        },
        dt = function(t, i) {
            var r = nt(n.examFieldCache[i]);
            r._isEditMode = !1;
            n.patientNewExamFields[i] = r;
            n.isDisableBtn = ut();
            tt(r)
        },
        gt = function(n) {
            n && (n._isAllChecked = !n._isAllChecked, n._isNotEmpty = n._isAllChecked, n.orthoFields && _.forEach(n.orthoFields, function(t) {
                t._readOnly || (t._isChecked = n._isAllChecked)
            }))
        },
        ni = function(n, t) {
            t._readOnly || (t._isChecked = !t._isChecked);
            n.orthoFields && (n._isAllChecked = !_.filter(n.orthoFields, function(n) {
                return !n._isChecked
            }).length > 0, n._isNotEmpty = _.any(n.orthoFields, function(n) {
                return n._isChecked
            }))
        },
        tt = function(t) {
            angular.forEach(n.fields, function(n) {
                n.id === t.id ? (n.active = !0, n.orthoFields && _.forEach(n.orthoFields, function(n) {
                    if (n.name === "发育情况" && n.orthoFields) {
                        var t = _.find(n.orthoFields, {
                            name: "月经"
                        });
                        if (t && t.value !== "无") return;
                        _.forEach(n.orthoFields, function(n) {
                            n.name === "初潮" && (n._disabled = t.value === "无")
                        })
                    }
                })) : n.active = !1
            })
        },
        ti = function(t) {
            for (var i, u, r, f = [], e = 0; e < t.orthoFields.length; e++)
                if ((i = angular.copy(t.orthoFields[e]), i._isChecked) && i.orthoFields)
                    if (i.orthoFields.length === 0) i.fieldName = i.name, i.fieldId = angular.copy(i.id), i.id = i.examFieldId, f.push(i);
                    else
                        for (u = 0; u < i.orthoFields.length; u++) r = angular.copy(i.orthoFields[u]), r.fieldName = r.name, r.fieldId = angular.copy(r.id), r.id = r.examFieldId, f.push(r);
            s.addPatientExamFields(f, n.patientId, t.id).success(function(i) {
                i && s.getPatientExamFields(n.patientId).success(function(i) {
                    n.patientExamFields = i;
                    nt(t);
                    t._isEditMode = !1;
                    n.isDisableBtn = ut();
                    tt(t);
                    n.showNotification("保存成功！")
                })
            })
        };
    var st = function(n) {
            n.orthoImageType === y.OrthoImageType.Denture ? n.isWidthLarger = n.width / n.height >= at : n.orthoImageType === y.OrthoImageType.Jaw && (n.isWidthLarger = n.width / n.height >= vt)
        },
        it = function() {
            var t = r.defer();
            return s.getPatientExamineImages(n.patientId).success(function(i) {
                var u, r, f;
                for (n.examImages = [], angular.forEach(i, function(t) {
                        t.image && n.examImages.push(t.image)
                    }), n.dentureImage = [], n.jawImage = [], r = 0; r < i.length; r++) u = i[r].image, u.position = i[r].position, u.imageDate = i[r].imageDate, u.inputId = "imageUploadPanel" + u.position + i[r].imageType, i[r].imageType === y.OrthoImageType.Denture && (u.orthoImageType = y.OrthoImageType.Denture, st(u), n.dentureImage.push(u)), i[r].imageType === y.OrthoImageType.Jaw && (u.orthoImageType = y.OrthoImageType.Jaw, st(u), n.jawImage.push(u));
                for (r = 0; r < 7; r++) ii(n.dentureImage, r);
                for (r = 0; r < 6; r++) ri(n.jawImage, r);
                n.dentureImage.sort(ot);
                n.jawImage.sort(ot);
                n.dentureImage.length < 9 && (f = n.dentureImage[n.dentureImage.length - 1].position + 1, n.dentureImage.push({
                    id: 0,
                    position: f,
                    title: "其他",
                    inputId: "imageUploadPanel" + f + "2",
                    orthoImageType: 2
                }));
                n.jawImage.length < 10 && (f = n.jawImage[n.jawImage.length - 1].position + 1, n.jawImage.push({
                    id: 0,
                    position: f,
                    title: "其他",
                    inputId: "imageUploadPanel" + f + "3",
                    orthoImageType: 3
                }));
                t.resolve(!0)
            }), t.promise
        },
        ii = function(n, t) {
            var i = _.find(n, function(n) {
                return n.position === t
            });
            if (!i) switch (t) {
                case 0:
                    n.push({
                        id: 0,
                        position: t,
                        title: "正位像",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    });
                    break;
                case 1:
                    n.push({
                        id: 0,
                        position: t,
                        title: "上牙列",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    });
                    break;
                case 2:
                    n.push({
                        id: 0,
                        position: t,
                        title: "左侧咬合",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    });
                    break;
                case 3:
                    n.push({
                        id: 0,
                        position: t,
                        title: "前牙覆牙合覆盖",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    });
                    break;
                case 4:
                    n.push({
                        id: 0,
                        position: t,
                        title: "下牙列",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    });
                    break;
                case 5:
                    n.push({
                        id: 0,
                        position: t,
                        title: "右侧咬合",
                        inputId: "imageUploadPanel" + t + "2",
                        orthoImageType: 2
                    })
            }
        },
        ri = function(n, t) {
            var i = _.find(n, function(n) {
                return n.position == t
            });
            if (!i) switch (t) {
                case 0:
                    n.push({
                        id: 0,
                        position: t,
                        title: "正面",
                        inputId: "imageUploadPanel" + t + "3",
                        orthoImageType: 3
                    });
                    break;
                case 1:
                    n.push({
                        id: 0,
                        position: t,
                        title: "正面微笑",
                        inputId: "imageUploadPanel" + t + "3",
                        orthoImageType: 3
                    });
                    break;
                case 2:
                    n.push({
                        id: 0,
                        position: t,
                        title: "侧位像",
                        inputId: "imageUploadPanel" + t + "3",
                        orthoImageType: 3
                    });
                    break;
                case 3:
                    n.push({
                        id: 0,
                        position: t,
                        title: "右侧面45度",
                        inputId: "imageUploadPanel" + t + "3",
                        orthoImageType: 3
                    });
                    break;
                case 4:
                    n.push({
                        id: 0,
                        position: t,
                        title: "左侧面45度",
                        inputId: "imageUploadPanel" + t + "3",
                        orthoImageType: 3
                    })
            }
        };
    var ui = function() {
            return "/app/orthdontic/views/orthdontic-image-upload.html"
        },
        nr = function() {
            return "/app/orthdontic/views/orthdontic-image-upload.html"
        },
        fi = function(t, i) {
            k = null;
            var r = $(t.target).parents(".image-item-border");
            n.currentPosition = parseInt(r.attr("position"));
            n.currentImageType = parseInt(r.attr("image-type"));
            $("#imageAppointmentDialog").css("display") !== "block" && ht(i)
        },
        tr = function() {
            var i = host.patient,
                t = r.defer(),
                u = {
                    patientId: i.id,
                    startTime: n.startTime,
                    notes: "影像创建的预约",
                    appointmentType: 1
                };
            return l.createAppointment(u).success(function(n) {
                n && t.resolve(n.id)
            }), t.promise
        },
        ei = function(t, i, r) {
            k = null;
            n.currentAppointmentId = t;
            n.categoryId = i;
            $("#" + r.inputId).click()
        },
        oi = function(t, i) {
            if ($(t.delegatedEvent.target).attr("id") == null) {
                if ($(t.delegatedEvent.target).parent().parent().attr("appointment-id") == null) return;
                if (n.categoryId == null) return
            }
            if (n.categoryId) {
                ft = null;
                k == null && bi();
                g++;
                var r = w.apiToken,
                    u = w.tokenType;
                i.url = w.apiHost + "/api/v1/ortho-field/upload?appointmentId=" + n.currentAppointmentId + "&categoryId=" + n.categoryId + "&position=" + n.currentPosition + "&type=" + n.currentImageType;
                i.headers = i.headers || {};
                i.headers.Authorization = u + " " + r;
                i.submit();
                n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable")
            }
        },
        si = function() {},
        hi = function() {},
        ci = function(n, t) {
            $("#image-upload-current").text("当前文件: " + t.files[0].name);
            $("#image-upload-all").text("已上传:" + d + "/" + (g + d));
            var i = parseInt(t.loaded / t.total * 99, 10);
            $("#image-upload-current-percent").css("width", i + "%")
        },
        li = function() {
            g--;
            d++;
            $("#image-upload-all").text("已上传:" + d + "/" + (g + d));
            var t = parseInt(d / (g + d) * 99, 10);
            $("#image-upload-all-percent").css("width", t + "%");
            g == 0 && ($(".close").show(), n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable"), $(".image-upload-finish").show(), d = 0, setTimeout(function() {
                k != null && (k.dismiss("close"), $(".close").click(), k = null)
            }, 3e3));
            it().then(function() {
                rt()
            })
        },
        ai = function() {
            k.dismiss("close");
            $(".close").show();
            k = null;
            g = 0;
            d = 0;
            b.error("错误", "文件上传失败！");
            n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable")
        },
        vi = function(t) {
            t && (t.marketCenterAccount = n.patient.marketCenterAccount, v.sendWeiXinImage(t).success(function() {
                b.info("信息", "图片微信已发送！")
            }).error(function(n) {
                u.error(n);
                alert(n)
            }))
        },
        yi = function(n) {
            ht(n)
        },
        pi = function(n) {
            b.confirm("确认", "确定删除此影像？").then(function() {
                s.deletePatientXrayImage(n).success(function() {
                    it().then(function() {
                        rt()
                    })
                }).error(function(n) {
                    u.error(n);
                    alert(n)
                })
            })
        },
        wi = function(n) {
            Ares.download(n.mediumSizeImageUrl)
        };
    var ut = function() {
            return _.any(n.patientNewExamFields, function(n) {
                return n._isEditMode
            })
        },
        ki = function(t) {
            var r, i, u;
            if ($(event.target).parent().parent().parent().hasClass("noclick")) {
                $(event.target).parent().parent().parent().removeClass("noclick");
                return
            }
            for (i = 0; i < n.appointmentsList.length; ++i) n.appointmentsList[i].id === t.appointmentId && (r = n.appointmentsList[i].previewImageList);
            u = e.open({
                animation: !0,
                backdrop: "static",
                template: "<image-detail-view><\/image-detail-view>",
                controller: "ImageDetailCtrl",
                windowClass: "image-detail-dialog",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            image: t,
                            allImages: r,
                            patient: n.patient
                        }
                    }
                }
            })
        },
        di = function(n, t) {
            n && n.name !== "月经" || t && t.orthoFields && _.forEach(t.orthoFields, function(t) {
                t.name === "初潮" && (t._disabled = n.value === "无")
            })
        };
    (function() {
        n.examFieldCache = {};
        n.patientId = o.patientId;
        n.itemClick = bt;
        n.allowEdit = kt;
        n.selectField = ni;
        n.allChecked = gt;
        n.handleKendoComboBoxChange = di;
        n.cancel = dt;
        n.save = ti;
        n.isDisableBtn = !1;
        yt();
        n.onClickFileDialog = fi;
        n.uploadStart = si;
        n.uploadStop = hi;
        n.uploadProgressed = ci;
        n.uploadFinished = li;
        n.uploadFailed = ai;
        n.addUpload = oi;
        n.onClickDeleteImage = pi;
        n.onChangeImage = yi;
        n.onClickSendWeixinImage = vi;
        n.categoryType = 0;
        n.onDownloadImage = wi;
        n.buildImageTemplateUrl = ui;
        n.openImage = ki;
        it().then(function() {
            rt()
        });
        c.getPatientLiteInfo(n.patientId, !0).success(function(t) {
            n.patient = t
        })
    })()
}]);
orthdonticModule.controller("OrthdonticEzcloudCtrl", ["$log", "$scope", "$modalInstance", "host", function(n, t, i, r) {
    "use strict";
    var u = function() {
        i.close()
    };
    (function() {
        t.close = u;
        t.patientId = r.patientId;
        t.seqNum = r.seqNum
    })()
}]);
orthdonticModule.controller("OrthdonticFileCtrl", ["$log", "$filter", "$scope", "$q", "$timeout", "$modal", "appointmentSvc", "patientSvc", "imagingSvc", "dataDicSvc", "aresDialog", "constants", "loginContext", "patientDocumentSvc", "enums", "orthoSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";

    function g() {
        var t = {
                patientId: i.patientId,
                endTime: moment(Ares.today()).add(1, "d").format(l.dateFormat),
                cancel: !1,
                isPending: !1
            },
            r = h.officeDic.data();
        e.searchAppointmentsByTenant(t).success(function(t) {
            var r, u;
            for (i.appointmentsList = t, r = 0; r < i.appointmentsList.length; ++r) u = ot(i.appointmentsList[r].officeId), i.appointmentsList[r].appointmentDescription = et(i.appointmentsList[r].startTime) + " " + u, ut(i.appointmentsList[r].id).then(function(n) {
                for (var t, r = 0; r < n.length; ++r) n[r].type = "preview";
                if (n.length > 0) {
                    for (t = 0; t < i.appointmentsList.length; ++t) i.appointmentsList[t].id == n[0].appointmentId && (i.appointmentsList[t].previewImageList = n, i.appointmentsList[t].allImageList = n);
                    i.categoryType != null && d(i.categoryType, !0)
                }
            }), v.getDocumentList(i.appointmentsList[r].id, 1).success(function(n) {
                for (var u, f, r, t = 0; t < n.length; ++t) n[t].type = "normal", n[t].thumbnailUrl = rt(n[t].filePath), n[t].isStl = n[t].filePath.toLocaleLowerCase().indexOf(".stl") > 0, n[t].isStl && (u = n[t].presignedUrl.indexOf("aliyuncs.com"), f = n[t].presignedUrl.indexOf(n[t].filePath), n[t].stlUrl = n[t].presignedUrl.substring(u + 13, f + n[t].filePath.length));
                if (n.length > 0)
                    for (r = 0; r < i.appointmentsList.length; ++r) i.appointmentsList[r].id == n[0].appointmentId && (i.appointmentsList[r].previewDocumentList = n, i.appointmentsList[r].allDocumentList = n)
            }).error(function(t) {
                n.error(t)
            })
        })
    }

    function ft(n) {
        for (var r, t = 0; t < i.appointmentsList.length; ++t)
            if (i.appointmentsList[t].allImageList != null)
                for (r = 0; r < i.appointmentsList[t].allImageList.length; r++)
                    if (i.appointmentsList[t].allImageList[r].id == n) return i.appointmentsList[t].allImageList[r];
        return null
    }

    function nt() {
        for (var t, n = 0; n < $(".col-md-11").size(); n++) $(".col-md-11").eq(n).attr("app-list-index") != null && (t = parseInt($(".col-md-11").eq(n).attr("app-list-index")), i.appointmentsList[t].allImageList == null && $($(".col-md-11")[n]).addClass("ng-hide"))
    }

    function ti() {
        w = f.open({
            animation: !0,
            backdrop: "static",
            template: "<image-upload-view><\/image-upload-view>",
            controller: "ImageUploadlCtrl",
            windowClass: ".image-upload-dialog",
            size: "lg",
            resolve: {
                host: function() {
                    return {
                        imageUploadDialog: w
                    }
                }
            }
        });
        setTimeout(function() {
            $(".close").hide()
        }, 200)
    }

    function ii() {
        var t, n;
        if (i.appointmentsList) {
            for (t = [], n = 0; n < i.appointmentsList.length; ++n) i.appointmentsList[n].isCancelled || t.push(i.appointmentsList[n]);
            it = f.open({
                animation: !0,
                backdrop: "static",
                template: "<image-select-appointment><\/image-select-appointment>",
                controller: "ImageAppointmentsCtrl",
                windowClass: "image-appointments-select-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            appointmentsList: t,
                            callback: lt,
                            patient: i.patient,
                            categoryType: i.categoryType,
                            usedFor: "orth"
                        }
                    }
                }
            })
        }
    }
    var et = t("toDateTimeString"),
        ei = t("toFirstVisit"),
        ot = t("toOfficeAbbr"),
        w = null,
        it = null,
        k = 0,
        b = 0,
        rt, ut, tt;
    i.currentImageList;
    i.progressBarPercentage = "0%";
    i.allImageList;
    i.categoryType = null;
    rt = function(n) {
        var t = n.substring(n.lastIndexOf("."));
        return t == ".doc" || t == ".docx" ? "/content/imgs/word-icon.png" : t == ".pdf" ? "/content/imgs/pdf-icon.png" : "/content/imgs/doc.jpg"
    };
    ut = function(n) {
        var t = r.defer();
        return s.getImagingListByAppointmentId(n).success(function(n) {
            t.resolve(n)
        }), t.promise
    };
    tt = {
        "1": "全景",
        "6": "口内照",
        "7": "面部照",
        "-1": "文档",
        "8": "STL数据",
        "3": "CBCT"
    };
    i.$on("ngRepeatFinished", function() {
        u(function() {
            $(".image-item-border[item-data-id]").kendoTooltip({
                autoHide: !0
            });
            $(".image-item-border[item-data-id]").draggable({
                appendTo: "body",
                zIndex: 9999,
                opacity: .65,
                revert: !0,
                start: function() {
                    $(this).addClass("noclick");
                    $(".col-md-11").removeClass("ng-hide")
                }
            });
            $(".image-item-category[category-value!=0]").droppable({
                hoverClass: "item-drop-hover",
                drop: function(n, t) {
                    var f = parseInt(t.draggable.attr("item-data-id")),
                        u = ft(f),
                        r;
                    u != null && (r = parseInt($(this).attr("category-value")), u.categoryId != r && (r != 5 || u.categoryId != -1)) && (c.customConfirm("提示", "你确定要将该影像的类型由" + tt[u.categoryId] + "修改为" + tt[r] + "吗？").then(function(n) {
                        var t, u;
                        if (n === "ok")
                            for (t = 0; t < i.appointmentsList.length; ++t)
                                if (i.appointmentsList[t].allImageList != null)
                                    for (u = 0; u < i.appointmentsList[t].allImageList.length; u++) i.appointmentsList[t].allImageList[u].id == f && (i.appointmentsList[t].allImageList[u].categoryId = r, s.updateImage(i.appointmentsList[t].allImageList[u]), d(i.categoryType, !1))
                    }), nt())
                }
            });
            $(".col-md-11").droppable({
                hoverClass: "item-drop-hover",
                drop: function(n, t) {
                    var e = parseInt(t.draggable.attr("item-data-id")),
                        f = parseInt($(this).attr("list-appointment-id")),
                        r = ft(e);
                    if (r == null || r.appointmentId == f) {
                        nt();
                        return
                    }
                    var o = _.find(i.appointmentsList, function(n) {
                            return n.id === r.appointmentId
                        }),
                        h = moment(o.startTime).format("YYYY-MM-DD HH:mm"),
                        l = _.find(i.appointmentsList, function(n) {
                            return n.id === f
                        }),
                        a = moment(l.startTime).format("YYYY-MM-DD HH:mm");
                    c.customConfirm("提示", "你确定要将该影像的就诊时间由" + h + "修改为" + a + "吗？").then(function(n) {
                        n === "ok" && u(function() {
                            for (var u, n, t = 0; t < i.appointmentsList.length; ++t)
                                if (i.appointmentsList[t].id == r.appointmentId)
                                    for (u = 0; u < i.appointmentsList[t].allImageList.length; u++)
                                        if (i.appointmentsList[t].allImageList[u].id == r.id) {
                                            i.appointmentsList[t].allImageList.splice(u, 1);
                                            break
                                        }
                            for (r.appointmentId = f, s.updateImage(r), n = 0; n < i.appointmentsList.length; ++n) i.appointmentsList[n].id == f && (i.appointmentsList[n].allImageList == null && (i.appointmentsList[n].allImageList = []), i.appointmentsList[n].previewImageList == null && (i.appointmentsList[n].previewImageList = []), i.appointmentsList[n].allImageList.push(r));
                            d(i.categoryType, !1)
                        })
                    });
                    nt()
                }
            })
        }, 200)
    });
    var d = function(n, t) {
            var r, u;
            if (t && (i.categoryType = n, $(".image-item-category-selected").removeClass("image-item-category-selected").addClass("image-item-category-unselected"), $("[category-value='" + n + "']").removeClass("image-item-category-unselected").addClass("image-item-category-selected")), n == y.ImageCategory.All)
                for (r = 0; r < i.appointmentsList.length; ++r) i.appointmentsList[r].previewImageList = i.appointmentsList[r].allImageList;
            else if (n == y.ImageCategory.FullView) {
                for (r = 0; r < i.appointmentsList.length; ++r)
                    if (i.appointmentsList[r].previewImageList = null, i.appointmentsList[r].allImageList != null)
                        for (u = 0; u < i.appointmentsList[r].allImageList.length; u++) i.appointmentsList[r].allImageList[u].categoryId == y.ImageCategory.FullView && (i.appointmentsList[r].previewImageList == null && (i.appointmentsList[r].previewImageList = []), i.appointmentsList[r].previewImageList.push(i.appointmentsList[r].allImageList[u]))
            } else if (n == y.ImageCategory.CBCT) {
                for (r = 0; r < i.appointmentsList.length; ++r)
                    if (i.appointmentsList[r].previewImageList = null, i.appointmentsList[r].allImageList != null)
                        for (u = 0; u < i.appointmentsList[r].allImageList.length; u++) i.appointmentsList[r].allImageList[u].categoryId == y.ImageCategory.CBCT && (i.appointmentsList[r].previewImageList == null && (i.appointmentsList[r].previewImageList = []), i.appointmentsList[r].previewImageList.push(i.appointmentsList[r].allImageList[u]))
            } else if (n == y.ImageCategory.MouthPhoto) {
                for (r = 0; r < i.appointmentsList.length; ++r)
                    if (i.appointmentsList[r].previewImageList = null, i.appointmentsList[r].allImageList != null)
                        for (u = 0; u < i.appointmentsList[r].allImageList.length; u++) i.appointmentsList[r].allImageList[u].categoryId == y.ImageCategory.MouthPhoto && (i.appointmentsList[r].previewImageList == null && (i.appointmentsList[r].previewImageList = []), i.appointmentsList[r].previewImageList.push(i.appointmentsList[r].allImageList[u]))
            } else if (n == y.ImageCategory.FacePhoto) {
                for (r = 0; r < i.appointmentsList.length; ++r)
                    if (i.appointmentsList[r].previewImageList = null, i.appointmentsList[r].allImageList != null)
                        for (u = 0; u < i.appointmentsList[r].allImageList.length; u++) i.appointmentsList[r].allImageList[u].categoryId == y.ImageCategory.FacePhoto && (i.appointmentsList[r].previewImageList == null && (i.appointmentsList[r].previewImageList = []), i.appointmentsList[r].previewImageList.push(i.appointmentsList[r].allImageList[u]))
            } else if (n == y.ImageCategory.STLData)
                for (r = 0; r < i.appointmentsList.length; ++r)
                    if (i.appointmentsList[r].previewImageList = null, i.appointmentsList[r].allImageList != null)
                        for (u = 0; u < i.appointmentsList[r].allImageList.length; u++) i.appointmentsList[r].allImageList[u].categoryId == y.ImageCategory.STLData && (i.appointmentsList[r].previewImageList == null && (i.appointmentsList[r].previewImageList = []), i.appointmentsList[r].previewImageList.push(i.appointmentsList[r].allImageList[u]))
        },
        st = function(n) {
            return "/app/common/components/image/" + n + "-image-item.html"
        },
        ht = function(n) {
            return "/app/common/components/document/" + n + "-document-item.html"
        },
        ct = function() {
            w = null;
            $("#imageAppointmentDialog").css("display") != "block" && ii()
        },
        oi = function() {
            var t = host.patient,
                n = r.defer(),
                u = {
                    patientId: t.id,
                    startTime: i.startTime,
                    notes: "影像创建的预约",
                    appointmentType: 1
                };
            return e.createAppointment(u).success(function(t) {
                t && n.resolve(t.id)
            }), n.promise
        },
        lt = function(n, t) {
            w = null;
            i.currentAppointmentId = n;
            i.categoryId = t;
            i.categoryId == -1 ? $("#fileUploadPanel").click() : $("#imageUploadPanel").click()
        },
        at = function(n, t) {
            if ($(n.delegatedEvent.target).attr("id") == null) {
                if ($(n.delegatedEvent.target).parent().parent().attr("list-appointment-id") == null) return;
                i.currentAppointmentId = parseInt($(n.delegatedEvent.target).parent().parent().attr("list-appointment-id"));
                i.categoryId == null && (i.categoryId = 4)
            }
            it = null;
            w == null && ti();
            k++;
            var r = a.apiToken,
                u = a.tokenType;
            t.url = i.categoryId == -1 ? a.apiHost + "/api/v1/patientdoc?appointmentId=" + i.currentAppointmentId + "&categoryId=1" : a.apiHost + "/api/v1/imaging?appointmentId=" + i.currentAppointmentId + "&categoryId=" + i.categoryId;
            t.headers = t.headers || {};
            t.headers.Authorization = u + " " + r;
            t.submit();
            i.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#imageUploadPanel").fileupload("enable")
        },
        vt = function() {},
        yt = function() {},
        pt = function(n, t) {
            $("#image-upload-current").text("当前文件: " + t.files[0].name);
            $("#image-upload-all").text("已上传:" + b + "/" + (k + b));
            var i = parseInt(t.loaded / t.total * 99, 10);
            $("#image-upload-current-percent").css("width", i + "%")
        },
        wt = function() {
            k--;
            b++;
            $("#image-upload-all").text("已上传:" + b + "/" + (k + b));
            var n = parseInt(b / (k + b) * 99, 10);
            $("#image-upload-all-percent").css("width", n + "%");
            k == 0 && ($(".close").show(), i.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#imageUploadPanel").fileupload("enable"), $(".image-upload-finish").show(), b = 0, setTimeout(function() {
                w != null && (w.dismiss("close"), $(".close").click(), w = null)
            }, 3e3), g())
        },
        bt = function() {
            w.dismiss("close");
            $(".close").show();
            w = null;
            k = 0;
            b = 0;
            c.error("错误", "文件上传失败！");
            i.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#imageUploadPanel").fileupload("enable")
        },
        kt = function(t) {
            t && (t.marketCenterAccount = i.patient.marketCenterAccount, s.sendWeiXinImage(t).success(function() {
                c.info("信息", "图片微信已发送！")
            }).error(function(t) {
                n.error(t);
                alert(t)
            }))
        },
        dt = function(n) {
            var t = n.comment;
            t == null && (t = "");
            c.inputConfirm("编辑", "输入影像备注", t).then(function() {
                n.comment = $(".ares-dialog-body input").val();
                s.updateImage(n)
            })
        },
        gt = function(t, r) {
            for (var u = 0; u < i.appointmentsList.length; ++u)
                if (i.appointmentsList[u].id == t.appointmentId) break;
            c.confirm("确认", "确定删除此影像？").then(function() {
                p.deletePatientXrayImage(t).success(function() {
                    i.appointmentsList[u].previewImageList.splice(r, 1);
                    for (var n = 0; n < i.appointmentsList[u].allImageList.length; n++) i.appointmentsList[u].allImageList[n].id == t.id && i.appointmentsList[u].allImageList.splice(n, 1)
                }).error(function(t) {
                    n.error(t);
                    alert(t)
                })
            })
        },
        ni = function(n) {
            Ares.download(n.mediumSizeImageUrl)
        };
    var ri = function(n) {
            var r, t, u;
            if ($(event.target).parent().parent().parent().hasClass("noclick")) {
                $(event.target).parent().parent().parent().removeClass("noclick");
                return
            }
            for (t = 0; t < i.appointmentsList.length; ++t) i.appointmentsList[t].id == n.appointmentId && (r = i.appointmentsList[t].previewImageList);
            u = f.open({
                animation: !0,
                backdrop: "static",
                template: "<image-detail-view><\/image-detail-view>",
                controller: "ImageDetailCtrl",
                windowClass: "image-detail-dialog",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            image: n,
                            allImages: r,
                            patient: i.patient
                        }
                    }
                }
            })
        },
        ui = function(n, t) {
            return n ? _.filter(n, {
                categoryId: t
            }).length : 0
        },
        fi = function(n) {
            c.confirm("确认", "确定删除此文档？").then(function() {
                v.deleteDocument(n.id).success(function() {
                    _.each(i.appointmentsList, function(t, i) {
                        t && t.previewDocumentList && _.filter(t.previewDocumentList, {
                            id: n.id
                        }).length > 0 && t.previewDocumentList.splice(i, 1)
                    })
                })
            })
        };
    (function() {
        n.debug("ImagingHistoryCtrl.initialize, patientId:" + i.patientId);
        i.enableWeixinSendImage = !1;
        o.getPatient(i.patientId).success(function(n) {
            i.patient = n;
            n.marketCenterAccount != null && n.marketCenterAccount != "" && (i.enableWeixinSendImage = !0)
        });
        i.buildImageTemplateUrl = st;
        i.buildDocumentTemplateUrl = ht;
        i.onClickFileDialog = ct;
        i.uploadStart = vt;
        i.uploadStop = yt;
        i.uploadProgressed = pt;
        i.uploadFinished = wt;
        i.uploadFailed = bt;
        i.addUpload = at;
        i.onClickDeleteImage = gt;
        i.onChangeImage = dt;
        i.onClickSendWeixinImage = kt;
        i.openImage = ri;
        i.filterImages = d;
        i.categoryType = 0;
        i.onDownloadImage = ni;
        i.loadAllApponitments = g;
        i.getImagesLength = ui;
        i.onClickDeleteDocument = fi;
        u(function() {
            g()
        }, 200)
    })()
}]);
orthdonticModule.controller("OrthdonticPlanCtrl", ["$scope", "$timeout", "$state", "$q", "$log", "$modal", "$stateParams", "orthoSvc", "dataDicSvc", "patientSvc", "aresDialog", "aresNotification", "loginContext", "printUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var w = a.officeId;
    n.allEditBtnState = !0;
    var b = function() {
            var t = r.defer();
            return o.getOrthoPlanCollectionByPatientId(n.patientId).success(function(i) {
                var u, f, o, r, s, h, e;
                if (n.patientPlanFields = i.patientPlanFields, n.chiefComplaint = i.planFields[2], n.correctionObjective = i.planFields[3], n.isCanEdit = i.isCanEdit, n.planFields = [], i.patientPlanFields) {
                    for (u = _.filter(i.planFields, function(n) {
                            return n.value
                        }), r = 0; r < u.length; r += 2) f = d(i.patientPlanFields, u[r].name), f = f ? f : null, r + 1 <= u.length ? (o = d(i.patientPlanFields, u[r + 1].name), o = o ? o : null, e = k(u[r]), e && e.value && (s = e.id), e = k(u[r + 1]), e && e.value && (h = e.id), n.planFields.push({
                        firstField: {
                            id: u[r].id,
                            name: u[r].name,
                            examFieldId: s,
                            value: y(u[r].value.split("|")),
                            selectValue: f && f.length > 0 ? f[0].value : null
                        },
                        secondField: {
                            id: u[r + 1].id,
                            name: u[r + 1].name,
                            examFieldId: h,
                            value: y(u[r + 1].value.split("|")),
                            selectValue: o && o.length > 0 ? o[0].value : null
                        }
                    })) : n.planFields.push({
                        firstField: {
                            id: u[r].id,
                            name: u[r].name,
                            examFieldId: s,
                            value: y(u[r].value.split("|")),
                            selectValue: f && f.length > 0 ? f[0].value : null
                        },
                        secondField: null
                    });
                    i.patientPlanFields[2] && i.patientPlanFields[2].fieldName === "主诉" && (n.chiefComplaint.value = i.patientPlanFields[2].value);
                    i.patientPlanFields[3] && i.patientPlanFields[3].fieldName === "矫治目标" && (n.correctionObjective.value = i.patientPlanFields[3].value)
                }
                n.plans = i.plans;
                n.isConcatEdit = !1;
                i.patientPlan && i.patientPlan.orthoPlanList.length > 0 ? (n.patientPlans = i.patientPlan, n.orthoPlanList = i.patientPlan.orthoPlanList, n.plans = i.plans, angular.forEach(n.orthoPlanList, function(n) {
                    tt(n.officeId);
                    n.isPlanEdit = !1;
                    n.recordCreatedTime = moment(n.recordCreatedTime).format("YYYY-MM-DD")
                }), n.selectPlan.id = i.patientPlan.selectedPlanId, n.selectPlans = angular.copy(n.orthoPlanList), wt(n.orthoPlanList)) : n.orthoPlanList && n.orthoPlanList.length !== 0 || nt();
                n.editExamNotes = [];
                n.patientExamNotes = i.examNotes;
                i.examNotes && _.each(i.examNotes, function(t) {
                    n.editExamNotes.push({
                        content: t.content,
                        seqNum: t.seqNum
                    })
                });
                n.editExamNotes.length === 0 && n.editExamNotes.push({
                    seqNum: 1
                });
                n.editExamNotesSnapshoot = angular.copy(n.editExamNotes);
                t.resolve(!0)
            }), t.promise
        },
        it = function(t) {
            o.getAllAgreementTemplates().then(function(i) {
                n.agreementTemplates = i.data;
                n.getSelectAgreementTemplate(t)
            })
        },
        y = function(n) {
            return _.map(n, function(n) {
                return typeof n == "string" ? {
                    name: n,
                    value: n
                } : n
            })
        },
        rt = function(n) {
            var t = s.officeDic.getItemSync(n);
            if (t) return t.abbreviation ? t.abbreviation : t.name
        },
        ut = function() {
            o.listAllSteps().success(function(t) {
                n.orthoSteps = t
            })
        },
        k = function(t) {
            return _.find(n.patientPlanFields, function(n) {
                return n.fieldId === t.id
            })
        },
        d = function(n, t) {
            return _.filter(n, function(n) {
                return n.fieldName === t
            })
        },
        ft = function() {
            for (var r, i = [], t = 0; t < n.planFields.length; t++) n.planFields[t].firstField && i.push({
                fieldId: n.planFields[t].firstField.id,
                fieldName: n.planFields[t].firstField.name,
                id: n.planFields[t].firstField.examFieldId,
                value: n.planFields[t].firstField.selectValue
            }), n.planFields[t].secondField && i.push({
                fieldId: n.planFields[t].secondField.id,
                fieldName: n.planFields[t].secondField.name,
                id: n.planFields[t].secondField.examFieldId,
                value: n.planFields[t].secondField.selectValue
            });
            i.push({
                fieldId: n.chiefComplaint.id,
                fieldName: n.chiefComplaint.name,
                id: n.chiefComplaint.parentId,
                value: n.chiefComplaint.value
            });
            i.push({
                fieldId: n.correctionObjective.id,
                fieldName: n.correctionObjective.name,
                id: n.correctionObjective.parentId,
                value: n.correctionObjective.value
            });
            r = _.filter(n.editExamNotes, function(n) {
                return n.content
            });
            _.each(r, function(n, t) {
                n.seqNum = t + 1
            });
            o.updatePatientExamNote(r, n.patientId).success(function(t) {
                n.patientExamNotes = t;
                t && o.addPatientPlanFields(i, n.patientId).success(function(t) {
                    t && o.getPatientPlanFields(n.patientId).success(function(t) {
                        n.patientPlanFields = t;
                        n.showNotification("保存成功！");
                        n.isFieldEdit = !1;
                        n.allEditBtnState = !0;
                        n.editExamNotesSnapshoot = angular.copy(n.editExamNotes);
                        b().then(function() {
                            p()
                        })
                    })
                })
            })
        },
        g = function(t) {
            n.patientPlan = {
                planId: t.id,
                name: t.name,
                patientId: n.patientId,
                price: t.price,
                unit: t.unit,
                note: t.note,
                fdiToothCodes: t.fdiToothCodes,
                toothDescription: t.toothDescription
            }
        },
        et = function(t, i) {
            var r, u;
            if (Array.isArray(t) && (t = t[0]), t.officeId || (t.officeId = w), r = t.steps, !r || r.length === 0) {
                n.showErrorNotification("保存失败,治疗步骤必须选择一项");
                return
            }
            u = t.fdiToothCodes;
            t.fdiToothCodes = ot(t.fdiToothCodes);
            o.updatePatientOrthoPlan(t).success(function(r) {
                l.success("保存成功");
                t.isPlanEdit = !1;
                n.allEditBtnState = !0;
                t.fdiToothCodes = u;
                n.orthoPlanList[i] = angular.copy(t);
                var f = _.find(n.orthoPlanList, {
                    id: t.id
                });
                f || (n.orthoPlanList[n.orthoPlanList.length - 1].id = r.id);
                n.selectPlans = angular.copy(n.orthoPlanList);
                n.calculationTotalCharge(t)
            })
        },
        ot = function(n) {
            return Array.isArray(n) && n.length > 0 ? n.join(",") : n
        },
        p = function() {
            var t = _.filter(n.planFields, function(n) {
                    return n.firstField.selectValue || n.secondField.selectValue
                }).length > 0,
                i = _.filter(n.patientExamNotes, function(n) {
                    return n.content
                }).length > 0;
            n.isFieldEdit = t || i || n.chiefComplaint.value || n.correctionObjective.value ? !1 : !0
        },
        st = function() {
            h.getPatientLiteInfo(n.patientId, !0).success(function(t) {
                n.patient = t;
                n.patient._sexStr = ht(t.sex);
                n.patient._birthStr = t.birth ? moment(t.birth).format("YYYY/MM/DD") : ""
            })
        },
        ht = function(n) {
            return n === 0 ? "女" : n === 1 ? "男" : ""
        },
        ct = function(t) {
            n.orthoPlanListCache = angular.copy(t);
            t.isPlanEdit = !0;
            n.allEditBtnState = !1;
            n.calculationTotalCharge(t)
        },
        lt = function(t, i) {
            n.orthoPlanList[i] = angular.copy(n.orthoPlanListCache);
            n.orthoPlanList[i].isPlanEdit = !1;
            n.allEditBtnState = !0;
            n.calculationTotalCharge(n.orthoPlanList[i])
        },
        at = function() {
            b().then(function() {
                p();
                st();
                it(n.orthoPlanList);
                ut()
            })
        },
        vt = function(t) {
            var i = f.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-setting-plan-plan-charge-choice-view><\/orthdontic-setting-plan-plan-charge-choice-view>",
                controller: "OrthdonticSettingPlanPlanChargeChoiceCtrl",
                windowClass: "membership-discountplan-detail-dialog",
                resolve: {
                    host: function() {
                        return {
                            chargeItemList: t.chargeItems
                        }
                    }
                }
            });
            i.result.then(function(i) {
                i && (t.chargeItems = i, n.calculationTotalCharge(t))
            })
        },
        yt = function(t, i) {
            t.chargeItems.splice(i, 1);
            n.calculationTotalCharge(t)
        },
        pt = function(n) {
            var r = n.chargeItems,
                t = 0,
                i = 0;
            angular.forEach(r, function(n) {
                i += parseInt(n.count);
                t += parseFloat(n.price) * parseInt(n.count)
            });
            n.totalCharge = t.toFixed(2);
            n.totalCount = i
        },
        wt = function(t) {
            for (var u, f, r, i = 0; i < t.length; i++)
                if (t[i].chargeItems.length !== 0)
                    for (u = 0, f = 0, r = 0; r < t[i].chargeItems.length; r++) u += parseInt(t[i].chargeItems[r].count), f += parseFloat(t[i].chargeItems[r].price) * parseInt(t[i].chargeItems[r].count), t[i].totalCount = u, t[i].totalCharge = f.toFixed(2);
            n.orthoPlanList = t
        },
        bt = function(t) {
            if (n.plans) {
                var i = _.filter(n.plans, {
                    name: t.name
                });
                i && i.length > 0 && t.isPlanEdit && (g(i[0]), t.note = i[0].note, o.getOrthoPlanSteps(i[0].id).success(function(n) {
                    t.steps = n;
                    t.steps && _.each(t.steps, function(n) {
                        t.name && (n.isChecked = !0)
                    })
                }), o.getPlan(i[0].id).success(function(i) {
                    t.chargeItems = i.chargeItems;
                    n.calculationTotalCharge(t)
                }))
            }
        },
        nt = function() {
            var t = {
                patientId: n.patientId,
                name: "",
                price: 0,
                duration: 0,
                unit: null,
                note: "",
                agreementTemplateId: null,
                code: null,
                pinyin: null,
                fdiToothCodes: null,
                toothDescription: null,
                isAgreed: !1,
                patient: null,
                steps: [],
                chargeItems: [],
                officeId: a.officeId,
                isPlanEdit: !0
            };
            n.orthoPlanList.push(t);
            n.orthoPlanListCache = angular.copy(n.orthoPlanList);
            n.allEditBtnState = !1
        },
        kt = function(n) {
            return rt(n)
        },
        tt = function(n) {
            return n ? n === w : !0
        },
        dt = function() {
            n.isConcatEdit = !0;
            n.allEditBtnState = !1;
            n.patientPlanCache = {};
            n.patientPlanCache = angular.copy(n.selectPlan)
        },
        gt = function() {
            var t = _.find(n.selectPlans, {
                id: parseInt(n.selectPlan.id)
            });
            if (!t) {
                n.isCanPrint = !1;
                n.isCanEdit = !1;
                n.showErrorNotification("请选择患者最终选定的方案");
                return
            }
            n.isConcatEdit = !1;
            n.isCanPrint = !0;
            n.allEditBtnState = !0;
            n.isSelectedPlan = !0;
            n.patientPlan.patientId = t.patientId;
            o.selectFinalPatientOrthoPlan(n.patientPlan.patientId, n.selectPlan.id).then(function(n) {
                n ? l.success("选择成功") : l.error("选择失败")
            })
        },
        ni = function(t) {
            c.confirm("提醒", "确定删除此正畸计划？").then(function() {
                o.deletePatientOrthoPlan(t.officeId, t.patientId, t.id).then(function(i) {
                    i ? (n.orthoPlanList = _.reject(n.orthoPlanList, {
                        id: t.id
                    }), n.selectPlans = angular.copy(n.orthoPlanList), l.success("删除成功")) : l.error("删除失败,请重试")
                })
            })
        },
        ti = function(i) {
            i.fdiToothCodes && (i.fdiToothCodes = Array.isArray(i.fdiToothCodes) ? i.fdiToothCodes : i.fdiToothCodes.split(","));
            n.showPlanSteps = i.steps;
            n.chargeItems = i.chargeItems;
            n.patientPlan = angular.copy(i);
            n.patientPlan.patientId = parseInt(n.patientId);
            n.getSelectAgreementTemplate(n.patientPlan);
            t(function() {
                n.printToothSelectorInstance.refresh();
                t(function() {
                    v.printElem("planTemplate")
                })
            })
        },
        ii = function() {
            n.isConcatEdit = !1;
            n.allEditBtnState = !0;
            n.selectPlan = angular.copy(n.patientPlanCache);
            n.isSelectedPlan = !!n.selectPlan.id
        };
    (function() {
        n.setSelectedPlan = g;
        n.selectedPlanName = null;
        n.isCanPrint = !1;
        n.saveFields = ft;
        n.savePlan = et;
        n.initClassShowOrEdit = p;
        n.editPlan = ct;
        n.chargeItems = [];
        n.showPlanSteps = [];
        n.selectedPlan = [];
        n.addChargeItems = vt;
        n.deleteChargeItem = yt;
        n.calculationTotalCharge = pt;
        n.orthoPlanList = [];
        n.hasChangedPlan = bt;
        n.addOrthoPlan = nt;
        n.showOfficeName = kt;
        n.getIsPlanEdit = tt;
        n.saveFinalPlan = gt;
        n.changePrintPlanState = ii;
        n.changePlanEditState = lt;
        n.changeState = dt;
        n.deletePatientPlan = ni;
        n.getPrintPatientOrthoPlan = ti;
        n.selectPlan = {};
        n.printToothSelectorInstance = null;
        at()
    })()
}]);
orthdonticModule.controller("OrthdonticProcessEditCtrl", ["$scope", "$rootScope", "$timeout", "$q", "$log", "$stateParams", "$state", "$modal", "aresDialog", "constants", "appointmentSvc", "practiceSvc", "apptUtil", "loginContext", "patientSvc", "dataDicSvc", "officeSvc", "aresNotification", "appNav", "enums", "aresTreeControlUtil", "patientUtil", "systemConfigUtil", "localCache", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d, g, nt, tt, it) {
    "use strict";
    var ct = it.getCache(it.keys.IsAllowSynchronizationOption),
        pt = function(n) {
            var t, i, r;
            if (n && n.oralCheckRecordList) {
                for (t = "", i = 0; i < n.oralCheckRecordList.length; ++i) n.oralCheckRecordList[i].description && (t = t + n.oralCheckRecordList[i].description, r = n.oralCheckRecordList[i].description.slice(-1), r != "。" && (t = t + "。"));
                return t != "。" ? t : ""
            }
            return ""
        },
        wt = function(n) {
            var t, i, r;
            if (n && n.cureRecordList) {
                for (t = "", i = 0; i < n.cureRecordList.length; ++i) n.cureRecordList[i].cure && (t = t + n.cureRecordList[i].cure, r = n.cureRecordList[i].cure.slice(-1), r != "。" && (t = t + "。"));
                return t != "。" ? t : ""
            }
            return ""
        },
        bt = function(n) {
            var i, t, r;
            if (n && n.treatmentAdviceList) {
                for (i = "", t = 0; t < n.treatmentAdviceList.length; ++t) n.treatmentAdviceList[t].content = n.treatmentAdviceList[t].content ? n.treatmentAdviceList[t].content : "", n.treatmentAdviceList[t].content && (i = i + n.treatmentAdviceList[t].content, r = n.treatmentAdviceList[t].content.slice(-1), r != "。" && (i = i + "。"));
                return i != "。" ? i : ""
            }
            return ""
        },
        kt = function() {
            n.currentOrthdonticTemplate = {
                templateName: "",
                Pinyin: "",
                diseaseId: null,
                oralCheck: pt(n.currentMedicalRecord),
                treatment: wt(n.currentMedicalRecord),
                advice: bt(n.currentMedicalRecord)
            };
            var t = o.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-process-template-save-view><\/orthdontic-process-template-save-view>",
                controller: "OrthdonticProcessTemplateSaveCtrl",
                windowClass: "emrtemplatesave-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            currentDiseaseId: n.currentDisease ? n.currentDisease.id : 0,
                            currentOrthdonticTemplate: n.currentOrthdonticTemplate,
                            templateTreeControl: n.templateTreeControl
                        }
                    }
                }
            });
            t.result.then(function() {}, function() {
                y.listEMRTemplates(d.TemplateType.Orthodontic).success(function(t) {
                    n.emrTemplates = t;
                    lt(n.diseaseItems, n.emrTemplates)
                })
            })
        },
        lt = function(t, i) {
            (n.templateTreeControl = new g.TreeControl(t, i), n.templateTreeControl) && (n.treeData = n.templateTreeControl.getTree(), n.topLevelNode = n.treeData)
        },
        dt = function() {
            y.listDiseaseItems(d.DiseaseType.Orthodontic).success(function(t) {
                n.diseaseItems = t;
                y.listEMRTemplates(d.TemplateType.Orthodontic).success(function(i) {
                    n.emrTemplates = i;
                    lt(t, i)
                })
            })
        },
        gt = function() {
            var t = r.defer();
            return w.getOfficeOrthoProcessSetting().success(function(i) {
                n.officeOptionSetings = i;
                n.isFdiToothEnabled = i.isFdiToothEnabled ? "1" : "0";
                t.resolve(!0)
            }), t.promise
        },
        ni = function() {
            n.orthdonticTemplateFieldsArray = [{
                parent: "orthdonticProcess",
                child: []
            }];
            (n.officeOptionSetings.isCheckFieldVisible || n.currentMedicalRecord.oralCheckRecordList.length > 0) && n.orthdonticTemplateFieldsArray[0].child.push("check");
            (n.officeOptionSetings.isCureFieldVisible || n.currentMedicalRecord.cureRecordList.length > 0) && n.orthdonticTemplateFieldsArray[0].child.push("cure");
            (n.officeOptionSetings.isAdviceFieldVisible || n.currentMedicalRecord.treatmentAdviceList.length > 0) && n.orthdonticTemplateFieldsArray[0].child.push("advice")
        },
        ti = function() {
            ii().then(function() {
                rr();
                gt().then(function() {
                    at().then(function() {
                        ni();
                        fi();
                        ri();
                        si();
                        dt();
                        oi().then(function() {
                            hi()
                        });
                        fr()
                    })
                })
            })
        },
        ii = function() {
            var t = r.defer();
            return p.doctorDic.loadActive().then(function(i) {
                n.providers = i;
                t.resolve(!0)
            }), t.promise
        },
        ri = function() {
            l.getOffice(v.officeId).success(function(t) {
                n.office = t
            })
        },
        ui = function(t) {
            var i = _.find(n.providers, function(n) {
                return n.id == t.doctorId
            });
            t.department = i ? i.department : ""
        },
        fi = function() {
            y.getPatient(n.patientId).success(function(t) {
                var i, r, u;
                n.patient = t;
                n.patient && (n.patient.birth ? (i = moment(n.patient.birth, "YYYY-MM-DD"), i.isValid() || (i = moment(n.patient.birth, "YYYYMMDD")), i.isValid() && (r = moment(Ares.today()), u = r.diff(i, "years"), n.ignoreAgeChanged = !0, n.patient.age = u)) : n.patient.age = "")
            })
        },
        ei = function() {
            var t = {
                doctorName: "",
                doctorId: 0,
                nurseName: "",
                nurseId: 0,
                recordDateTime: moment(new Date).format("YYYY-MM-DD HH:mm:ss"),
                cureRecordList: [],
                oralCheckRecordList: [],
                treatmentAdviceList: []
            };
            // n.officeOptionSetings.isCheckFieldVisible && t.oralCheckRecordList.push(rt("检查"));
            n.officeOptionSetings.isCureFieldVisible && t.cureRecordList.push(rt("处置"));
            n.officeOptionSetings.isAdviceFieldVisible && t.treatmentAdviceList.push(rt("医嘱"));
            _.extend(n.currentMedicalRecord, t)
        },
        at = function() {
            var t = r.defer(),
                i;
            return n.isUpdating = !0, n.isEdit ? (i = e.params.recordId || n.currentMedicalRecord.id, y.getMedicalRecord(i).success(function(i) {
                n.currentMedicalRecord = i;
                ft(i);
                n.isUpdating = !1;
                t.resolve(!0)
            })) : (n.currentMedicalRecord = {
                id: 0,
                patientId: n.patientId,
                appointId: 0,
                medicalRecordType: 1,
                doctorName: "",
                doctorId: 0,
                nurseName: "",
                nurseId: 0,
                recordDateTime: moment(new Date).format("YYYY-MM-DD HH:mm:ss"),
                cureRecordList: [],
                oralCheckRecordList: [],
                treatmentAdviceList: []
            }, ft(n.currentMedicalRecord), n.isUpdating = !1, t.resolve(!0)), t.promise
        },
        oi = function() {
            var t = r.defer();
            return l.getDoctors().success(function(i) {
                n.doctors = i;
                t.resolve(!0)
            }), t.promise
        },
        si = function() {
            var t = [];
            p.nurseDic.loadActive().then(function(i) {
                angular.forEach(i, function(n) {
                    t.push(n)
                });
                p.assistantDic.loadActive().then(function(i) {
                    angular.forEach(i, function(n) {
                        t.push(n)
                    });
                    n.nurses = t
                })
            })
        },
        ft = function(t) {
            var u = r.defer(),
                i;
            if (t.oralCheckRecordList && t.oralCheckRecordList.length > 0)
                for (i = 0; i < t.oralCheckRecordList.length; ++i) t.oralCheckRecordList[i].fdiToothCodesArray = t.oralCheckRecordList[i].fdiToothCodes != null && t.oralCheckRecordList[i].fdiToothCodes != "" ? t.oralCheckRecordList[i].fdiToothCodes.split(",") : t.oralCheckRecordList[i].fdiToothCodesArray || [], t.oralCheckRecordList[i].description && (t.oralCheckRecordList[i].descriptionStr = t.oralCheckRecordList[i].description.replace(/\n/g, "<br/>"));
            else n.officeOptionSetings.isCheckFieldVisible && t.oralCheckRecordList.push(rt("检查"));
            if (t.cureRecordList && t.cureRecordList.length > 0)
                for (i = 0; i < t.cureRecordList.length; ++i) t.cureRecordList[i].fdiToothCodesArray = t.cureRecordList[i].fdiToothCodes != null && t.cureRecordList[i].fdiToothCodes != "" ? t.cureRecordList[i].fdiToothCodes.split(",") : t.cureRecordList[i].fdiToothCodesArray || [], t.cureRecordList[i].cure && (t.cureRecordList[i].cureStr = t.cureRecordList[i].cure.replace(/\n/g, "<br/>"));
            else n.officeOptionSetings.isCureFieldVisible && t.cureRecordList.push(rt("处置"));
            if (t.treatmentAdviceList && t.treatmentAdviceList.length > 0)
                for (i = 0; i < t.treatmentAdviceList.length; ++i) t.treatmentAdviceList[i].fdiToothCodesArray = t.treatmentAdviceList[i].fdiToothCodes != null && t.treatmentAdviceList[i].fdiToothCodes != "" ? t.treatmentAdviceList[i].fdiToothCodes.split(",") : t.treatmentAdviceList[i].fdiToothCodesArray || [], t.treatmentAdviceList[i].content && (t.treatmentAdviceList[i].contentStr = t.treatmentAdviceList[i].content.replace(/\n/g, "<br/>"));
            else n.officeOptionSetings.isAdviceFieldVisible && t.treatmentAdviceList.push(rt("医嘱"));
            return ui(t), n.isChanged = !1, u.resolve(!0), u.promise
        },
        vt = function(t) {
            var i = o.open({
                animation: !0,
                backdrop: "static",
                template: "<appt-list-dialog><\/appt-list-dialog>",
                controller: "apptListDialogCtrl",
                size: "md",
                resolve: {
                    host: function() {
                        return {
                            apptList: t,
                            patientId: n.patientId,
                            type: "emr"
                        }
                    }
                }
            });
            i.result.then(function(t) {
                t && (n.selectDropDown(t.id, "appoint"), v.isDoctor ? n.selectDropDown(v.providerId, "doctor") : n.selectDropDown(t.doctorId, "doctor"), n.currentMedicalRecord.firstVisit = t.isFirstVisit, n.currentMedicalRecord.appointId = t.id, n.appt.startTime = t.startTime)
            })
        },
        hi = function() {
            var t = {
                officeId: v.officeId,
                patientId: n.patientId,
                endTime: moment(Ares.today()).add(1, "d").format(h.dateFormat),
                isCancelled: !1,
                isPending: !1,
                isFailed: !1
            };
            c.searchAppointments(t).success(function(t) {
                var e, r, f, o, l;
                if (t.length > 0) {
                    for (n.isEnabledTimePicker(!1), e = angular.copy(t), r = 0; r < t.length; ++r) t[r].startTimeStr = moment(t[r].startTime).format("YYYY年MM月DD日 HH:mm");
                    if (n.historyAppts = t, n.currentMedicalRecord.id == 0) {
                        n.currentMedicalRecord.appointId = t[0].id;
                        n.currentMedicalRecord.firstVisit = t[0].isFirstVisit;
                        n.currentMedicalRecord.doctorId = t[0].doctorId;
                        n.selectDropDown(t[0].doctorId, "doctor");
                        var s = moment(Ares.today()).format(h.dateFormat),
                            c = moment(Ares.today()).add(1, "d").format(h.dateFormat),
                            u = _.filter(e, function(n) {
                                return n.startTime >= s && n.startTime < c
                            });
                        u && u.length > 1 && vt(u)
                    }
                } else f = et(), n.isEnabledTimePicker(!0), o = moment(f.startTime).format("YYYY年MM月DD日 HH:mm"), l = {
                    startTimeStr: o,
                    id: -2,
                    startTime: f.startTime
                }, n.historyAppts = [], i(function() {
                    li()
                })
            })
        },
        ci = function() {
            var i = $("#appoint").data("kendoDropDownList"),
                t = {
                    officeId: v.officeId,
                    patientId: n.patientId,
                    startTime: moment(n.appt.startTime).format(h.dateFormat),
                    endTime: moment(n.appt.startTime).add(1, "d").format(h.dateFormat),
                    isCancelled: !1,
                    isFailed: !1,
                    isPending: !1
                };
            c.searchAppointmentsByTenant(t).success(function(t) {
                var u, i, e;
                if (n.isEnabledTimePicker(!1), t.length == 1) n.selectDropDown(t[0].id, "appoint"), n.currentMedicalRecord.appointId = t[0].id, v.isDoctor ? n.selectDropDown(v.providerId, "doctor") : n.selectDropDown(t[0].doctorId, "doctor");
                else if (t.length > 1) u = angular.copy(t), vt(u);
                else {
                    i = et();
                    n.isEnabledTimePicker(!0);
                    var o = moment(i.startTime).format("YYYY年MM月DD日 HH:mm"),
                        f = {
                            startTimeStr: o,
                            id: -2,
                            startTime: i.startTime
                        },
                        s = _.filter(n.historyAppts, function(n) {
                            return n.id != -2
                        }),
                        r = angular.copy(s);
                    n.tempHistoryAppts = r;
                    n.tempAppointTime = i.startTime;
                    r.push(f);
                    n.currentMedicalRecord.appointId = -2;
                    e = _.find(n.historyAppts, function(n) {
                        return !n.isFailed && !n.isCanceled
                    });
                    e != null && (i.isFirstVisit = !1);
                    n.refreshApptDropDown(f, r)
                }
            })
        },
        li = function() {
            var t = et(),
                u = moment(t.startTime).format("YYYY年MM月DD日 HH:mm"),
                r = {
                    startTimeStr: u,
                    id: -2,
                    startTime: t.startTime
                },
                i = angular.copy(n.historyAppts),
                f;
            n.tempHistoryAppts = i;
            n.tempAppointTime = t.startTime;
            i.push(r);
            n.currentMedicalRecord.appointId = -2;
            f = _.find(n.historyAppts, function(n) {
                return !n.isFailed && !n.isCanceled
            });
            n.refreshApptDropDown(r, i)
        },
        et = function() {
            var t = ai();
            return {
                startTime: t.startDate,
                endTime: t.endDate,
                patientId: n.patientId,
                doctorId: n.currentMedicalRecord.doctorId,
                isFirstVisit: n.currentMedicalRecord.firstVisit
            }
        },
        ai = function() {
            var r = new Date,
                t, i, u, f;
            return n.appt.startTime = n.appt.startTime || r, n.appt.startTime.setHours(r.getHours()), n.appt.startTime.setMinutes(r.getMinutes()), t = moment(n.appt.startTime), i = moment().format("mm") * 1, i < 15 ? t.minutes(15) : i > 15 && i < 30 ? t.minutes(30) : i > 30 && i < 45 ? t.minutes(45) : i > 45 && (t.minutes(0), t.add(1, "hour")), u = moment(t).format("YYYY-MM-DD HH:mm"), f = moment(u).add(30, "m").format("YYYY-MM-DD HH:mm"), {
                startDate: u,
                endDate: f
            }
        },
        or = function(t, i, r) {
            a.confirmDoctorSchedule(i).then(function(t) {
                t.canSave && c.createAppointment(i).success(function(t) {
                    n.currentMedicalRecord.firstVisit = t.isFirstVisit;
                    n.currentMedicalRecord.appointId = t.id;
                    var i = {
                        officeId: v.officeId,
                        patientId: n.patientId,
                        endTime: moment(Ares.today()).add(1, "d").format(h.dateFormat),
                        cancel: !1
                    };
                    c.searchAppointmentsByTenant(i).success(function(i) {
                        if (i.length > 0) {
                            n.historyAppts = i;
                            for (var u = 0; u < n.historyAppts.length; ++u) n.historyAppts[u].startTimeStr = moment(n.historyAppts[u].startTime).format("YYYY年MM月DD日 HH:mm");
                            r && r(t)
                        } else n.historyAppts = []
                    })
                })
            })
        },
        vi = function(t, i) {
            n.isInput = !0;
            var r = $("#emrTabs").kendoTabStrip().data("kendoTabStrip");
            r && (t == "检查" ? r.select(2) : t == "处置" ? r.select(6) : t == "医嘱" && r.select(5));
            n.currentFocusControlName = t;
            i != null ? (n.currentFocusControlName == "检查" ? n.currentOralCheckRecord = n.currentMedicalRecord.oralCheckRecordList[i] : n.currentFocusControlName == "处置" ? n.currentCureRecord = n.currentMedicalRecord.cureRecordList[i] : n.currentFocusControlName == "医嘱" && (n.treatmentAdvice = n.currentMedicalRecord.treatmentAdviceList[i]), n.selectedIndex = i) : n.selectedIndex = null
        },
        rt = function(n) {
            return n == "检查" ? {
                id: 0,
                description: "",
                fdiToothCodesArray: [],
                fdiToothCodes: ""
            } : n == "处置" ? {
                id: 0,
                cure: "",
                fdiToothCodesArray: []
            } : n == "医嘱" ? {
                id: 0,
                content: "",
                fdiToothCodesArray: []
            } : void 0
        },
        yi = function(t, i) {
            i > 0 && (t == "检查" ? n.currentMedicalRecord.oralCheckRecordList.splice(i, 1) : t == "处置" ? n.currentMedicalRecord.cureRecordList.splice(i, 1) : t == "医嘱" && n.currentMedicalRecord.treatmentAdviceList.splice(i, 1))
        },
        pi = function(t) {
            t == "检查" ? n.currentMedicalRecord.oralCheckRecordList.push(rt("检查")) : t == "处置" ? n.currentMedicalRecord.cureRecordList.push(rt("处置")) : t == "医嘱" && n.currentMedicalRecord.treatmentAdviceList.push(rt("医嘱"))
        },
        wi = function(t) {
            n.currentMedicalRecord && n.currentMedicalRecord.oralCheckRecordList && (n.currentMedicalRecord.oralCheckRecordList[n.currentMedicalRecord.oralCheckRecordList.length - 1].description = t.oralCheck);
            n.currentMedicalRecord && n.currentMedicalRecord.cureRecordList && (n.currentMedicalRecord.cureRecordList[n.currentMedicalRecord.cureRecordList.length - 1].cure = t.treatment);
            n.currentMedicalRecord.isShowTreatmentAdviceList && n.currentMedicalRecord && n.currentMedicalRecord.treatmentAdviceList && (n.currentMedicalRecord.treatmentAdviceList[n.currentMedicalRecord.treatmentAdviceList.length - 1].content = t.treatmentAdvice)
        },
        bi = function(t) {
            switch (t) {
                case "检查":
                    n.currentMedicalRecord && n.currentMedicalRecord.oralCheckRecordList && (n.currentMedicalRecord.oralCheckRecordList[n.currentMedicalRecord.oralCheckRecordList.length - 1].description = "");
                    break;
                case "处置":
                    n.currentMedicalRecord && n.currentMedicalRecord.cureRecordList && (n.currentMedicalRecord.cureRecordList[n.currentMedicalRecord.cureRecordList.length - 1].cure = "");
                    break;
                case "医嘱":
                    n.currentMedicalRecord && n.currentMedicalRecord.treatmentAdviceList && (n.currentMedicalRecord.treatmentAdviceList[n.currentMedicalRecord.treatmentAdviceList.length - 1].content = "")
            }
        },
        ki = function(n, t) {
            !n && t ? wi(t) : bi(n, t)
        },
        yt = function() {
            return angular.copy(n.currentMedicalRecord)
        },
        di = function(t) {
            var f, u, r;
            if (Ares.ensureNotDuplicated("OnEmrSaved")) {
                if (n.getDoctor() == -1) {
                    s.warn("信息", "请选择一个医生！");
                    return
                }
                if (!n.currentMedicalRecord.appointId) {
                    s.warn("信息", "没有关联的就诊时间，请先创建一次预约，填写正畸过程！");
                    return
                }
                if (f = gi(), f) {
                    s.warn("信息", f);
                    return
                }
                if (n.historyAppts = angular.copy(n.tempHistoryAppts || n.historyAppts), u = _.find(n.historyAppts, function(t) {
                        return t.id == n.currentMedicalRecord.appointId
                    }), n.isEnableEMRWritingLimitValue && n.EMRWritingLimitValue >= 0 && moment(u.startTime).add(n.EMRWritingLimitValue, "d").format("YYYY-MM-DD") < moment(Ares.today()).format("YYYY-MM-DD")) {
                    s.warn("信息", "已经超过正畸过程补写限时" + n.EMRWritingLimitValue + "天");
                    return
                }
                n.isUpdating = !0;
                n.currentMedicalRecord.appointDateTime = u ? u.startTime : null;
                n.setNurse();
                n.setDoctor();
                r = angular.copy(n.currentMedicalRecord);
                r.cureRecordList = nr();
                r.oralCheckRecordList = tr();
                r.treatmentAdviceList = ir();
                r.id == 0 ? y.createMedicalRecord(r).success(function(r) {
                    var u, f;
                    n.currentMedicalRecord.id = r.id;
                    n.currentMedicalRecord.appointId == -2 && (u = _.find(n.historyAppts, function(t) {
                        return t.id == n.currentMedicalRecord.appointId
                    }), u.id = r.appointId, n.currentMedicalRecord.appointId = r.appointId);
                    f = n.currentMedicalRecord.appointId;
                    t && c.completeAppointment(f).success(function() {
                        k.allowLeave();
                        n.goToList("patientOrthdontic.process")
                    });
                    n.originalMedicalRecord = yt();
                    i(function() {
                        n.isChanged = !1;
                        n.isUpdating = !1;
                        n.isEdit = !0;
                        b.success("保存成功");
                        n.initPrint();
                        k.allowLeave()
                    })
                }).error(function() {
                    s.warn("信息", "记录保存失败")
                }) : y.updateMedicalRecord(r).success(function(r) {
                    var u, f;
                    n.currentMedicalRecord.appointId == -2 && (u = _.find(n.historyAppts, function(t) {
                        return t.id == n.currentMedicalRecord.appointId
                    }), u.id = r, n.currentMedicalRecord.appointId = r);
                    f = n.currentMedicalRecord.appointId;
                    t ? c.completeAppointment(f).success(function() {
                        k.allowLeave();
                        n.goToList("patientOrthdontic.process")
                    }) : at();
                    n.originalMedicalRecord = yt();
                    i(function() {
                        n.isChanged = !1;
                        n.isUpdating = !1;
                        b.success("保存成功");
                        k.allowLeave()
                    })
                }).error(function() {
                    s.warn("信息", "记录保存失败")
                })
            }
        },
        gi = function() {
            var t = _.any(n.currentMedicalRecord.oralCheckRecordList, function(n) {
                return n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 && n.description == ""
            });
            return t ? "【检查】中牙位缺少描述。" : (t = _.any(n.currentMedicalRecord.treatmentAdviceList, function(n) {
                return n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 && n.content == ""
            }), t) ? "【医嘱】中牙位缺少描述。" : (t = _.any(n.currentMedicalRecord.cureRecordList, function(n) {
                return n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 && n.cure == ""
            }), t) ? "【处置】中牙位缺少描述。" : ""
        },
        nr = function() {
            var t = [];
            return angular.forEach(n.currentMedicalRecord.cureRecordList, function(n) {
                var i = ot(n.cure);
                i.length > 0 && (n.fdiToothCodes = n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 ? n.fdiToothCodesArray.join(",") : "", t.push(n))
            }), t
        },
        tr = function() {
            var t = [];
            return angular.forEach(n.currentMedicalRecord.oralCheckRecordList, function(n) {
                var i = ot(n.description);
                i.length > 0 && (n.fdiToothCodes = n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 ? n.fdiToothCodesArray.join(",") : "", t.push(n))
            }), t
        },
        ir = function() {
            var t = [];
            return angular.forEach(n.currentMedicalRecord.treatmentAdviceList, function(n) {
                var i = ot(n.content);
                i.length > 0 && (n.fdiToothCodes = n.fdiToothCodesArray && n.fdiToothCodesArray.length > 0 ? n.fdiToothCodesArray.join(",") : "", t.push(n))
            }), t
        },
        ot = function(n) {
            return !n || !angular.isString(n) ? "" : n.replace(/(^\s*)|(\s*$)/g, "")
        },
        rr = function() {},
        st = function(t, i, r) {
            var u = angular.copy(n.currentMedicalRecord[t]);
            u[i] && (u[i].fdiToothCodesArray = r, n.currentMedicalRecord[t] = angular.copy(u))
        },
        ut = function() {
            var t = n.recordTooth.index,
                u = n.currentMedicalRecord[n.recordTooth.name][t],
                r;
            u && t == 0 && (n.Synching = !0, r = u.fdiToothCodesArray, n.recordTooth.name != "oralCheckRecordList" && st("oralCheckRecordList", t, r), n.recordTooth.name != "cureRecordList" && st("cureRecordList", t, r), n.recordTooth.name != "treatmentAdviceList" && st("treatmentAdviceList", t, r), i(function() {
                n.Synching = !1
            }, 100))
        },
        ur = function(t) {
            n.isInput = !1;
            var r = t.attr("data-list-name"),
                i = t.attr("data-index");
            n.recordTooth = n.isAllowSynchronization && i == "0" ? {
                name: r,
                index: parseInt(i)
            } : null
        },
        sr = function(n) {
            angular.forEach(n, function(n) {
                n.fdiToothCodes = n.fdiToothCodesArray.join(",")
            })
        },
        ht = function() {
            return n.currentMedicalRecord && n.isAllowSynchronization && n.Synching == !1 && n.recordTooth != null && n.isInput == !1
        },
        fr = function() {
            if (n.currentMedicalRecord && n.currentMedicalRecord.id <= 0) {
                n.isAllowSynchronization = !0;
                var t = ct.loadObject();
                t && (n.isAllowSynchronization = t.isAllowSynchronization)
            }
        },
        hr = function() {
            if (n.currentMedicalRecord && n.currentMedicalRecord.id <= 0) {
                var t = {
                    isAllowSynchronization: n.isAllowSynchronization
                };
                ct.saveObject(t)
            }
        },
        er = function() {
            nt.hasCheckedInToday(f.patientId).then(function(t) {
                n.isCheckedInToday = t.isCheckedIn;
                n.isStrongStrict = t.isStrongStrict
            });
            tt.getConfigValue(tt.configKeys.EMRWritingLimit).then(function(t) {
                n.EMRWritingLimitValue = t
            });
            tt.getConfigValue(tt.configKeys.IsEnableEMRWritingLimit).then(function(t) {
                n.isEnableEMRWritingLimitValue = t || !1
            })
        };
    (function() {
        n.date = new Date;
        n.appt = {};
        n.today = new Date;
        n.isUpdating = !1;
        n.isAllowSynchronization = !1;
        n.Synching = !1;
        n.isEdit = e.params.recordId > 0;
        n.patientId = f.patientId;
        n.onApptTimeChanged = ci;
        n.addEMRControl = pi;
        n.deleteEMRControl = yi;
        n.setEMRControlFocus = vi;
        n.saveEmr = di;
        n.clear = ei;
        n.setEmrField = ki;
        n.formatMedicalRecord = ft;
        n.toothSynchronization = ut;
        n.onRecordTooth = ur;
        n.showSaveOrthdonticProcessTemplateDlg = kt;
        n.isInput = !1;
        n.isCheckedInToday = !1;
        n.isStrongStrict = !1;
        n.isEnableEMRWritingLimitValue = !1;
        n.EMRWritingLimitValue = 0;
        ti();
        er();
        n.$watch("currentMedicalRecord.oralCheckRecordList", function() {
            ht() && ut()
        }, !0);
        n.$watch("currentMedicalRecord.cureRecordList", function() {
            ht() && ut()
        }, !0);
        n.$watch("currentMedicalRecord.treatmentAdviceList", function() {
            ht() && ut()
        }, !0)
    })()
}]);
emrModule.controller("OrthdonticProcessTemplateCategoryChoiceCtrl", ["$log", "$scope", "$modalInstance", "loginContext", "host", function(n, t, i, r, u) {
    "use strict";
    var f = u.treeControl,
        e = f.getTree(),
        o = function() {
            i.dismiss("cancel")
        },
        s = function() {
            i.close(t.chosenCategory)
        },
        h = {
            showActionBar: !1,
            showLeafs: !1
        };
    t.selectNode = function(n) {
            t.chosenCategory.id = n.id;
            t.chosenCategory.departmentName = n.departmentName;
            t.chosenCategory.breadcrumb = f.getBranchBreadcrumbById(n.id).join(" > ");
            t.templateCaetegoryNotChosen = !1
        },
        function() {
            t.treeControl = f;
            t.treeData = e;
            t.treeOpts = h;
            t.cancel = o;
            t.close = s;
            t.templateCaetegoryNotChosen = !0;
            t.chosenCategory = {
                id: null,
                breadcrumb: "",
                departmentName: ""
            }
        }()
}]);
orthdonticModule.controller("OrthdonticProcessTemplateSaveCtrl", ["$log", "$scope", "$modalInstance", "host", function(n, t, i, r) {
    "use strict";
    t.cancel = function() {
            i.dismiss("cancel")
        },
        function() {
            t.templateTreeControl = r.templateTreeControl;
            t.currentOrthdonticTemplate = r.currentOrthdonticTemplate;
            t.currentDiseaseId = r.currentDiseaseId
        }()
}]);
orthdonticModule.controller("OrthdonticProcessCtrl", ["$scope", "$timeout", "$state", "$q", "$log", "$stateParams", "$modal", "enums", "aresDialog", "aresNotification", "patientSvc", "practiceSvc", "dataDicSvc", "loginContext", "permissionProvider", "systemConfigUtil", "officeOptionSvc", "patientDocumentSvc", "officeSvc", "printTemplateUtil", "patientUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d) {
    "use strict";
    var rt = function() {
            et().then(function() {
                ot().then(function() {
                    ft()
                })
            })
        },
        nt = function(t) {
            n.date = new Date;
            n.printTemplateConfig = {
                configName: "orthdontic",
                coments: "emrPrint"
            };
            var i = t && t.configName == "orthdontic" ? r.when(t.configValue) : p.getConfigValue("orthdontic");
            i.then(function(t) {
                if (t && t != "") {
                    var i = t;
                    n.printTemplateConfig.isHide = !1;
                    n.printTemplateConfig.templateCode = i;
                    i.indexOf("Orthdontic") < 0 && (n.printTemplateConfig.isHide = !0);
                    d.getTemplateByCode(i).then(function(t) {
                        n.printTemplate = t
                    })
                } else n.printTemplateConfig.isHide = !0
            })
        },
        ut = function() {
            var n = e.open({
                animation: !0,
                backdrop: "static",
                template: "<emr-print-configuration-view><\/emr-print-configuration-view>",
                controller: "emrPrintConfigurationCtrl",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            template: "orthdontic"
                        }
                    }
                }
            });
            n.result.then(function(n) {
                nt(n)
            })
        },
        ft = function() {
            c.getSpecialTypeMedicalRecordsByPatientId(n.patientId, 1).success(function(t) {
                if (tt(t), n.medicalRecords = t, n.copyMedicalRecords = angular.copy(n.medicalRecords), n.medicalRecords) {
                    var i = _.findIndex(n.medicalRecords, function(t) {
                        return t.medicalRecordId == n.medicalRecordId
                    });
                    i = i > -1 ? i : 0;
                    n.medicalRecords[i] && !n.medicalRecords[i].isDocument && (it(n.medicalRecords[i]), n.autoScroll())
                }
            })
        },
        tt = function(t) {
            var i = !1,
                r = !1,
                u = !1,
                f = !1;
            angular.forEach(t, function(e) {
                var o, h, a;
                e.className = "detail" + e.id;
                e.color = "#00A8CB";
                e.startTimeStr = moment(e.startTime).format("YYYY-MM-DD");
                e.isDocument || (o = _.find(n.providers, function(n) {
                    return n.id == e.doctorId
                }), e.doctorName = o ? o.name : "", e.department = o ? o.department : "");
                var s = moment(e.startTimeStr),
                    v = moment(Ares.today()).format("YYYY-MM-DD"),
                    b = moment(Ares.today()).startOf("month"),
                    c = moment(Ares.today()).add(-30, "d"),
                    l = moment(Ares.today()).add(-180, "d"),
                    y = moment(Ares.today()).startOf("year"),
                    p = moment(c).format("YYYY") == moment(Ares.today()).format("YYYY"),
                    w = moment(l).format("YYYY") == moment(Ares.today()).format("YYYY");
                v == e.startTimeStr ? i ? (e.dateStr = null, e.tag = "今日") : (e.dateStr = "今日", e.tag = "今日", i = !0) : s >= c && p ? r ? (e.dateStr = null, e.tag = "一个月") : (e.dateStr = "一个月", e.tag = "一个月", r = !0) : s >= l && w ? u ? (e.dateStr = null, e.tag = "半年") : (e.dateStr = "半年", e.tag = "半年", u = !0) : s >= y ? f ? (e.dateStr = null, e.tag = "今年") : (e.dateStr = "今年", e.tag = "今年", f = !0) : (h = moment(s).format("YYYY") + "年", a = _.find(t, function(n) {
                    return n.dateStr == h
                }), e.dateStr = a ? null : h, e.tag = h, e.color = "#9397A2");
                e.dateStr && (n.lastEmrTag = e.dateStr)
            })
        },
        et = function() {
            var t = r.defer();
            return a.doctorDic.load().then(function(i) {
                n.providers = i;
                t.resolve(!0)
            }), t.promise
        },
        ot = function() {
            var t = r.defer();
            return k.getOfficeOrthoProcessSetting().success(function(i) {
                n.allowToothFDI = i ? i.isFdiToothEnabled : !1;
                n.allowEditTooth = i ? i.isToothSelectorEnabled : !1;
                n.isFdiToothEnabled = i ? i.isFdiToothEnabled ? "1" : "0" : "1";
                n.orthoFieldVisibilities = {
                    check: i.isCheckFieldVisible,
                    cure: i.isCureFieldVisible,
                    advice: i.isAdviceFieldVisible
                };
                t.resolve(!0)
            }), t.promise
        },
        g = function(n) {
            for (var t = 0; t < n.length; t++) n[t].fdiToothCodeArray = angular.copy(n[t].fdiToothCodes)
        },
        it = function(t) {
            t != null && (t.isDocument || (t.isShowDetail ? t.isShowDetail = !1 : t.hasDetailData ? (t.isShowDetail = !0, n.setHeight(t)) : c.getFullMedicalRecord(t.medicalRecordId).success(function(i) {
                t.hasDetailData = !0;
                t.oralCheckRecordList = i.oralCheckRecordList;
                t.cureRecordList = i.cureRecordList;
                t.treatmentAdviceList = i.treatmentAdviceList;
                g(t.oralCheckRecordList);
                g(t.cureRecordList);
                g(t.treatmentAdviceList);
                t.nurseName = i.nurseName;
                t.appointDateTime = i.appointDateTime;
                t.planPrice = i.planPrice;
                t.isShowDetail = !0;
                n.setHeight(t);
                var r = a.officeDic.getItemSync(i.officeId);
                r && (t.officeName = r.abbreviation);
                n.clickEmrCount = n.clickEmrCount + 1
            })))
        },
        st = function(t, i) {
            s.confirm("提醒", "确定要删除此正畸过程？").then(function() {
                c.deleteMedicalRecord(t.medicalRecordId).success(function() {
                    n.medicalRecords.splice(i, 1);
                    tt(n.medicalRecords);
                    h.success("删除成功")
                }).error(function(n) {
                    h.success("删除失败");
                    u.log(n)
                })
            })
        },
        ct = function() {
            c.getPatient(n.patientId).success(function(t) {
                var i, r, u;
                n.patient = t;
                n.patient && (n.patient.birth ? (i = moment(n.patient.birth, "YYYY-MM-DD"), i.isValid() || (i = moment(n.patient.birth, "YYYYMMDD")), i.isValid() && (r = moment(Ares.today()), u = r.diff(i, "years"), n.ignoreAgeChanged = !0, n.patient.age = u)) : n.patient.age = "")
            })
        },
        ht = function(t) {
            var i = _.filter(n.medicalRecords, function(n) {
                    return n.tag == t.tag
                }),
                r = !t.isHide,
                f = i && r ? i.length : 0,
                u;
            angular.forEach(i, function(n, t) {
                n.isHide = r;
                n.tagCount = f;
                n.isHideTimeLine = t > 0 && r ? !0 : !1
            });
            u = _.filter(n.medicalRecords, function(n) {
                return !n.isHide
            });
            n.showMedicalRecordCount = u ? u.length : 0
        };
    (function() {
        n.clickEmrCount = 1;
        n.medicalRecordId = (i.params.medicalRecordId || 0) * 1;
        n.date = new Date;
        n.patientId = f.patientId;
        n.showDetail = it;
        n.deleteEMR = st;
        n.onToggleEmr = ht;
        n.toPrint = ut;
        nt();
        rt()
    })()
}]);
orthdonticModule.controller("orthdonticSettingPlanAgreementDialogCtrl", ["$log", "$q", "$scope", "$modalInstance", "orthoSvc", "aresNotification", function(n, t, i, r, u, f) {
    "use strict";
    var e, o = function() {
            r.close()
        },
        s = function() {
            var n = t.defer();
            return i.agreementTemplate.displayOrder = e.length, u.addAgreementTemplate(i.agreementTemplate).then(function() {
                f.success("保存成功");
                n.resolve(!0);
                r.close()
            }), n.promise
        },
        h = function() {
            u.getAllAgreementTemplates().then(function(n) {
                e = n.data
            })
        };
    (function() {
        i.close = o;
        i.saveForm = s;
        h()
    })()
}]);
orthdonticModule.controller("orthdonticSettingPlanAgreementCtrl", ["$scope", "$timeout", "$state", "$q", "$log", "$stateParams", "orthoSvc", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
            e.getAllAgreementTemplates().then(function(t) {
                n.agreementTemplates = t.data
            })
        },
        s = function(n) {
            var t = r.defer();
            return e.updateAgreementTemplate(n).then(function() {
                t.resolve(!0)
            }), t.promise
        },
        h = function(n) {
            var t = r.defer();
            return e.deleteAgreementTemplate(n).then(function() {
                t.resolve(!0)
            }), t.promise
        };
    (function() {
        n.saveTemplateChange = s;
        n.deleteTemplate = h;
        n.initData = o;
        o()
    })()
}]);
orthdonticModule.controller("OrthdonticSettingPlanDiagnosticConfigCtrl", ["$q", "$scope", "orthoSvc", "patientSvc", "loginContext", "aresNotification", "constants", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
            var u = n.defer();
            return r.listOrthdonticTemplateTreeItems().success(function(n) {
                var r = n || [];
                i.getDiagnosticConfig().success(function(n) {
                    n.forEach(n => n.items = n.subTypeItems);
                    r.unshift({
                        mainType: "正畸词条-牙型与骨型",
                        subTypes: n
                    });
                    t.diagnosticConfigData = r;
                    u.resolve()
                })
            }), u.promise
        },
        s = function(n) {
            var r = t.currentSubType.subType,
                u = {
                    subType: r,
                    subTypeItems: n
                };
            i.updateDiagnosticConfig(u).success(function() {
                t.currentSubTypeCache.items = angular.copy(n);
                t.isEdit = !1;
                f.success("保存成功！")
            })
        },
        h = function(n) {
            var u, i;
            u = t.diagnosticConfigData.length === 0 ? [t.currentMainTypeConfig] : t.diagnosticConfigData.slice(1, t.diagnosticConfigData.length);
            i = [];
            angular.forEach(u, function(t) {
                var r = t.mainType;
                angular.forEach(t.subTypes, function(t) {
                    if (t.subTypeId == n && t.items.length > 0) angular.forEach(t.items, function(n, u) {
                        var f = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder,
                            id: n.id ? n.id : 0,
                            itemCode: "",
                            itemName: n.itemContent,
                            itemContent: n.itemContent,
                            order: u,
                            mainType: r
                        };
                        i.push(f)
                    });
                    else if (t.subTypeId == n && t.items.length === 0) {
                        var u = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder,
                            id: 0,
                            itemCode: "",
                            itemName: "",
                            itemContent: "",
                            order: "",
                            mainType: r
                        };
                        i.push(u)
                    }
                })
            });
            i = JSON.stringify(i);
            r.updateEMRTemplateItem(i).success(function() {
                t.currentSubTypeCache.items = angular.copy(i);
                t.isEdit = !1;
                f.success("保存成功！")
            })
        },
        c = function(n, i) {
            r.deleteEMRTemplateItemSubType(n).success(function() {
                t.currentMainTypeConfig.subTypes.splice(i, 1);
                t.currentMainTypeConfig.subTypes.length === 0 ? t.currentSubType = null : (t.currentSubType = t.currentMainTypeConfig.subTypes[0], t.currentSubType.selected = !0);
                f.success("删除成功！")
            })
        };
    (function() {
        t.saveDiagnosticItemContent = s;
        t.saveOrthdonticItemContent = h;
        t.diagnosticSubTypes = e.diagnosticSubType;
        t.deleteSubTypeItem = c;
        t.initDiagnosticConfig = o
    })()
}]);
orthdonticModule.controller("OrthdonticSettingPlanPlanChargeChoiceCtrl", ["$log", "$scope", "$modalInstance", "$q", "membershipSvc", "aresDialog", "dataDicSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = {},
        h = {},
        c = function(n) {
            var i = n[0],
                r = n[1],
                u = n[2];
            t.chargeSupCatagoryList = [];
            i.forEach(function(n) {
                t.chargeSupCatagoryList.push(n);
                s[n.id] = []
            });
            r.forEach(function(n) {
                var i = _.findIndex(t.chargeSupCatagoryList, function(t) {
                    return n.itemSuperCategoryId == t.id ? !0 : !1
                });
                i != -1 && (s[n.itemSuperCategoryId].push(n), h[n.id] = [])
            });
            u.forEach(function(n) {
                var t = s[n.itemSuperCategoryId],
                    i;
                if (t) {
                    if (i = _.findIndex(t, function(t) {
                            return n.itemCatagoryId == t.id ? !0 : !1
                        }), i == -1) return
                } else return;
                h[n.itemCatagoryId].push(n)
            });
            t.defaultSupCategoryId = t.chargeSupCatagoryList.length > 0 ? t.chargeSupCatagoryList[0].id : 0;
            t.chargeCatagoryList = s[t.defaultSupCategoryId];
            t.chargeCatagoryList && t.chargeCatagoryList.length > 0 && (t.defaultCategoryId = t.chargeCatagoryList[0].id);
            t.chargeItemList = h[t.defaultCategoryId]
        },
        l = function() {
            t.giftPlanList = [];
            t.existList && t.existList.length > 0 && _.each(t.existList, function(n) {
                var i = {
                    id: n.chargeItemId,
                    itemId: n.chargeItemId,
                    itemName: n.chargeItemName,
                    count: n.count,
                    price: n.price
                };
                t.giftPlanList.push(i)
            })
        },
        a = function() {
            i.dismiss("cancel")
        },
        v = function() {
            var n = [];
            _.each(t.giftPlanList, function(t) {
                var i = {
                    chargeItemId: t.id,
                    chargeItemName: t.itemName,
                    count: t.count,
                    price: t.price
                };
                n.push(i)
            });
            i.close(n)
        },
        y = function(n, i) {
            t.chargeItemList = null;
            n ? t.chargeItemList = h[n] : i && (t.chargeCatagoryList = s[i], t.chargeCatagoryList && t.chargeCatagoryList.length > 0 && (t.defaultCategoryId = t.chargeCatagoryList[0].id, t.chargeItemList = h[t.defaultCategoryId]))
        };
    (function() {
        t.existList = o.chargeItemList;
        t.save = v;
        t.cancel = a;
        t.resetChargeItemList = y;
        t.chargeSupCatagoryList = null;
        t.chargeCatagoryList = null;
        t.chargeItemList = null;
        t.defaultSupCategoryId = 0;
        t.defaultCategoryId = 0;
        l();
        r.all([e.chargeSuperCategoryDic.load(), e.chargeCategoryDic.load(), e.chargeItemDic.load(), ]).then(function(n) {
            c(n)
        })
    })()
}]);
orthdonticModule.controller("OrthdinticSettingPlanPlanDialogCtrl", ["$log", "$scope", "$location", "$modalInstance", "$http", "$state", "$modal", "aresDialog", "appNav", "orthoSvc", "dataDicSvc", "enums", "constants", "loginContext", "host", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    var w = y.orthoAllPlans,
        b = function() {
            r.dismiss("cancel")
        },
        k = function() {
            h.listAllSteps().success(function(n) {
                t.orthoSteps = n
            })
        },
        d = function() {
            y.planId ? (t.title = "编辑治疗方案项目", t.isEdit = !0, h.getPlan(y.planId).success(function(n) {
                t.treatmentPlan = n;
                t.planCode = n.code;
                t.planName = n.name
            })) : (t.title = "新建治疗方案项目", t.isEdit = !1, t.treatmentPlan = {
                code: "",
                name: "",
                isInactive: !1,
                note: "",
                steps: [],
                chargeItems: []
            })
        },
        g = function() {
            var n = e.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-setting-plan-plan-charge-choice-view><\/orthdontic-setting-plan-plan-charge-choice-view>",
                controller: "OrthdonticSettingPlanPlanChargeChoiceCtrl",
                windowClass: "membership-discountplan-detail-dialog",
                resolve: {
                    host: function() {
                        return {
                            chargeItemList: t.treatmentPlan.chargeItems
                        }
                    }
                }
            });
            n.result.then(function(n) {
                n && (t.treatmentPlan.chargeItems = n)
            })
        },
        nt = function(n) {
            t.treatmentPlan.chargeItems.splice(n, 1)
        },
        tt = function(n, i) {
            var u = n.sender,
                r = u.value();
            r == null && (u.value(1), t.treatmentPlan.chargeItems[i].count = 1, r = 1);
            t.treatmentPlan.chargeItems[i].count = r
        },
        it = function() {
            var n = !1,
                i = !1;
            if (angular.forEach(t.orthoAllPlans, function(r) {
                    var u = r.code,
                        f = r.name;
                    u && u == t.treatmentPlan.code && (n = !0);
                    f && f == t.treatmentPlan.name && (i = !0)
                }), t.treatmentPlan.code == t.planCode && (n = !1), n) {
                o.info("提示", "方案代码重复");
                return
            }
            if (t.treatmentPlan.name == t.planName && (i = !1), i) {
                o.info("提示", "方案名称重复");
                return
            }
            t.treatmentPlan.id ? h.updatePlan(t.treatmentPlan).success(function(n) {
                p.success("保存成功！");
                r.close(n)
            }).error(function() {}) : h.addPlan(t.treatmentPlan).success(function(n) {
                p.success("保存成功！");
                r.close(n)
            }).error(function() {})
        };
    (function() {
        t.cancel = b;
        t.addChargeItems = g;
        t.deleteChargeItem = nt;
        t.onItemCountChange = tt;
        t.savePlan = it;
        t.orthoAllPlans = w;
        k();
        d()
    })()
}]);
orthdonticModule.controller("OrthdonticSettingPlanPlanCtrl", ["$log", "$scope", "$location", "$window", "$modal", "$http", "aresDialog", "appNav", "orthoSvc", "dataDicSvc", "loginContext", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var a = function() {
            s.listAllPlan().success(function(n) {
                t.orthoAllPlans = n;
                t.orthoIsInactivePlans = [];
                angular.forEach(n, function(n) {
                    n.isInactive || t.orthoIsInactivePlans.push(n)
                });
                t.orthoPlans = t.showIsEableOrAll ? t.orthoAllPlans : t.orthoIsInactivePlans
            })
        },
        v = function(n) {
            s.changePlanStatus(n.id, !n.isInactive).success(function() {
                var i = "启用";
                n.isInactive || (i = "禁用");
                l.success(i + "成功！");
                t.browserPlans()
            })
        };
    (function() {
        a();
        t.browserPlans = a;
        t.changeSelectPlan = v
    })()
}]);
orthdonticModule.controller("OrthdinticSettingPlanSetpDialogCtrl", ["$log", "$scope", "$location", "$modalInstance", "$http", "$state", "aresDialog", "appNav", "orthoSvc", "dataDicSvc", "enums", "constants", "loginContext", "host", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y) {
    "use strict";
    var p = function() {
            r.dismiss("cancel")
        },
        w = function() {
            t.orthoStep.id ? s.updateStep(t.orthoStep).success(function(n) {
                y.success("保存成功！");
                h.orthoStepDic.refresh();
                r.close(n)
            }).error(function() {}) : s.addStep(t.orthoStep).success(function(n) {
                y.success("保存成功！");
                h.orthoStepDic.refresh();
                r.close(n)
            }).error(function() {})
        },
        b = function() {
            jQuery.validator.addMethod("valCode", function(n) {
                var u = !0,
                    r, i;
                if (n)
                    for (r = h.orthoStepDic.data(), i = 0; i < r.length; ++i)
                        if (r[i].code === n)
                            if (t.orthoStep.id == r[i].id) continue;
                            else {
                                u = !1;
                                return
                            }
                return u
            }, "编码已被使用！");
            jQuery.validator.addMethod("valName", function(n) {
                var u = !0,
                    r, i;
                if (n)
                    for (r = h.orthoStepDic.data(), i = 0; i < r.length; ++i)
                        if (r[i].name === n)
                            if (t.orthoStep.id == r[i].id) continue;
                            else {
                                u = !1;
                                return
                            }
                return u
            }, "名称已被使用！")
        };
    (function() {
        t.orthoStep = {};
        h.orthoStepDic.load();
        b();
        t.id = v.id;
        t.orthoStep = t.id > 0 ? h.orthoStepDic.getItemSync(t.id) : {
            id: 0,
            name: "",
            code: "",
            pinyin: ""
        };
        t.cancel = p;
        t.saveStep = w
    })()
}]);
orthdonticModule.controller("OrthdonticSettingPlanStepCtrl", ["$log", "$scope", "$location", "$window", "$modal", "$http", "aresDialog", "appNav", "orthoSvc", "dataDicSvc", "loginContext", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var a = function() {
            s.listAllSteps().success(function(n) {
                t.orthoSteps = n
            })
        },
        v = function() {
            var n = u.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-setting-plan-step-dialog-view><\/orthdontic-setting-plan-step-dialog-view>",
                controller: "OrthdinticSettingPlanSetpDialogCtrl",
                size: "md",
                resolve: {
                    host: function() {
                        return {
                            id: 0
                        }
                    }
                }
            });
            n.result.then(function() {
                t.browserSteps();
                h.orthoStepDic.refresh()
            })
        },
        y = function(n) {
            var i = u.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-setting-plan-step-dialog-view><\/orthdontic-setting-plan-step-dialog-view>",
                controller: "OrthdinticSettingPlanSetpDialogCtrl",
                size: "md",
                resolve: {
                    host: function() {
                        return {
                            id: n.id
                        }
                    }
                }
            });
            i.result.then(function() {
                t.browserSteps();
                h.orthoStepDic.refresh()
            })
        },
        p = function(n) {
            e.confirm("提示", "确定要删除此步骤？").then(function() {
                s.deleteStep(n.id).success(function() {
                    l.success("删除成功！");
                    t.browserSteps();
                    h.orthoStepDic.refresh()
                })
            })
        };
    (function() {
        a();
        t.isDisableDbClick = !1;
        t.browserSteps = a;
        t.createStep = v;
        t.editStep = y;
        t.deleteStep = p
    })()
}]);
orthdonticModule.controller("OrthdonticSettingProcessBasicConfigCtrl", ["$log", "$scope", "officeSvc", "officeOptionSvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    var f = function() {
            i.updateOfficeOrthoProcessSetting(t.orthoProcessSetting).success(function() {
                u.success("保存成功");
                t.isEdit = !1
            })
        },
        e = function() {
            i.getOfficeOrthoProcessSetting().success(function(n) {
                t.orthoProcessSetting = n
            })
        };
    (function() {
        t.isEdit = !1;
        t.orthoProcessSetting = {};
        t.saveOrthoProcessSettings = f;
        e()
    })()
}]);
orthdonticModule.controller("OrthdonticSettingProcessTemplateConfigCtrl", ["$log", "$scope", "$location", "$http", "$q", "$modal", "appNav", "aresNotification", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "officeOptionSvc", "officeUtil", "aresTreeControlUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w) {
    "use strict";
    t.currentEmrTemplate = {};
    t.backupEmrTemplate = {};
    t.isEditEmrTemplate = !1;
    t.topLevelNode = {};
    t.secondLevelNode = {};
    t.opts = {
        dirSelectable: !1
    };
    var b = function(n, i) {
            (t.templateTreeControl = new w.TreeControl(n, i), t.templateTreeControl) && (t.treeData = t.templateTreeControl.getTree())
        },
        k = function(n) {
            t.expandedNodes = [];
            h.listDiseaseItems(l.DiseaseType.Orthodontic).success(function(t) {
                h.listEMRTemplates(n).success(function(n) {
                    b(t, n)
                })
            })
        },
        d = function() {
            t.savedEmrTemplate = angular.copy(t.currentEmrTemplate);
            t.isEditEmrTemplate = !0
        },
        g = function() {
            h.updateEMRTemplate(t.currentEmrTemplate).success(function(n) {
                o.success("保存成功");
                t.templateTreeControl.updateLeaf(n)
            }).error(function(t) {
                n.debug(t)
            });
            t.isEditEmrTemplate = !1
        },
        nt = function() {
            t.currentEmrTemplate = angular.copy(t.savedEmrTemplate);
            t.isEditEmrTemplate = !1
        },
        tt = function() {
            var n = u.defer();
            return y.getOfficeOption(y.optionKeys.IsEmrCustomTemplateEnabled).then(function(i) {
                i && (t.isEmrCustomTemplateEnabled = !0);
                n.resolve(!0)
            }), n.promise
        },
        it = function() {
            var n = u.defer();
            return p.isParentEnabled("EMR").then(function(i) {
                t.isEMRParentEnabled = i;
                n.resolve(!0)
            }), n.promise
        },
        rt = function(n) {
            var i = f.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-template-config-directory-move-view><\/orthdontic-template-config-directory-move-view>",
                controller: "OrthdonticTemplateConfigDirectoryMoveCtrl",
                windowClass: "practice-emrtemplate-browser-directory-move",
                resolve: {
                    host: function() {
                        return {
                            currentEmrTemplate: n,
                            treeControl: t.templateTreeControl,
                            templateType: t.templateType,
                            diseaseItemName: t.diseaseItemName
                        }
                    }
                }
            });
            i.result.then(function(n) {
                t.selectedNode = {};
                t.currentEmrTemplate = {};
                t.templateTreeControl.moveLeaf(n)
            })
        };
    (function() {
        t.currentDiseaseItem = null;
        t.initEHRParentEnabled = it;
        t.initOfficeOption = tt;
        t.constructEMRTemplateTreeData = b;
        t.cancelEmrTemplate = nt;
        t.saveEmrTemplate = g;
        t.editEmrTemplate = d;
        t.browserEMRTemplateSetting = k;
        t.moveEmrTemplate = rt
    })()
}]);
orthdonticModule.controller("OrthdonticSettingProcessTemplateItemConfigCtrl", ["$log", "$scope", "$location", "$http", "$q", "$modal", "appNav", "aresNotification", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "officeOptionSvc", "officeUtil", "aresDialog", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var l = function() {
            h.listOrthdonticTemplateTreeItems().success(function(n) {
                t.orthdonticTemplateItemSettingData = n;
                n.length > 0 && (angular.forEach(n, function(n) {
                    n.mainType == t.mainType && (t.subTypesMap = n)
                }), t.subTypesMap.subTypes.length > 0 && (t.subItems = t.subTypesMap.subTypes[t.showItemIndex]))
            })
        },
        a = function(n, i) {
            h.deleteEMRTemplateItemSubType(n).success(function() {
                t.subTypesMap.subTypes.splice(i, 1);
                t.subTypesMap.subTypes.length === 0 && (t.subItems = []);
                o.success("删除成功！")
            })
        },
        v = function(n) {
            var f = angular.copy(t.subItems),
                i = {},
                r = [],
                u;
            angular.forEach(n, function(n) {
                i.subTypeId = n.subTypeId;
                i.subType = n.subType;
                i.subTypeOrder = n.subTypeOrder;
                u = n.mainType;
                var t = {
                    id: n.id,
                    itemCode: n.itemCode,
                    itemName: n.itemContent,
                    itemContent: n.itemContent,
                    order: n.order
                };
                r.push(t)
            });
            i.items = r;
            t.subItems = i;
            n.length == 0 && (t.subItems = f);
            angular.forEach(t.orthdonticTemplateItemSettingData, function(n) {
                n.mainType == u && angular.forEach(n.subTypes, function(n) {
                    n.subTypeId == t.subItems.subTypeId && (n.items = t.subItems.items)
                })
            })
        },
        y = function(n) {
            var r, i;
            r = t.orthdonticTemplateItemSettingData.length === 0 ? [t.subTypesMap] : t.orthdonticTemplateItemSettingData;
            i = [];
            angular.forEach(r, function(t) {
                var r = t.mainType;
                angular.forEach(t.subTypes, function(t) {
                    var f = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder
                        },
                        u;
                    t.subTypeId == n && t.items.length > 0 ? angular.forEach(t.items, function(n, u) {
                        var f = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder,
                            id: n.id ? n.id : 0,
                            itemCode: "",
                            itemName: n.itemContent,
                            itemContent: n.itemContent,
                            order: u,
                            mainType: r
                        };
                        i.push(f)
                    }) : t.subTypeId == n && t.items.length === 0 && (u = {
                        subTypeId: t.subTypeId,
                        subType: t.subType,
                        subTypeOrder: t.subTypeOrder,
                        id: 0,
                        itemCode: "",
                        itemName: "",
                        itemContent: "",
                        order: "",
                        mainType: r
                    }, i.push(u))
                })
            });
            i = JSON.stringify(i);
            h.updateEMRTemplateItem(i).success(function(n) {
                v(n);
                t.isEdit = !1;
                o.success("保存成功！")
            })
        },
        p = function() {
            c.orthTemplateItemMainTypeDic.load().then(function(n) {
                t.orthdonticTemplateItemSettingMainTypes = [];
                n.forEach(function(n) {
                    n.itemName != "正畸词条-主诉" && n.itemName != "正畸词条-问题" && n.itemName != "正畸词条-目标" && t.orthdonticTemplateItemSettingMainTypes.push(n.itemName)
                });
                t.mainType = t.orthdonticTemplateItemSettingMainTypes[0];
                t.subTypesMap = {
                    mainType: t.mainType,
                    subTypes: []
                };
                l()
            })
        };
    (function() {
        t.deleteSubTypeItem = a;
        t.saveOrthdonticItemContent = y;
        t.showSubTypeIndex = 0;
        t.showItemIndex = 0;
        t.subItems = {
            items: []
        };
        p()
    })()
}]);
orthdonticModule.controller("OrthdonticTemplateConfigCreateItemCtrl", ["$log", "$scope", "$modalInstance", "host", "enums", function(n, t, i, r, u) {
    "use strict";
    var h = function() {
            i.dismiss("cancel")
        },
        e = r.type,
        f = r.itemData,
        o, s;
    switch (e) {
        case 1:
            t.title = "修改目录名称";
            t.newDiseaseItem = angular.copy(f);
            break;
        case 2:
            t.title = "新增目录";
            t.newDiseaseItem = {
                itemName: "",
                parentId: f.id,
                pinyin: "",
                ownerId: null
            };
            break;
        case 3:
            t.title = "新增模板";
            t.newEMRTemplate = {
                templateName: "",
                Pinyin: "",
                diseaseId: f.id,
                diseaseName: f.itemName,
                oralCheck: "",
                treatment: "",
                advice: "",
                userId: null,
                templateType: u.TemplateType.Orthodontic
            };
            t.isEmrCustomTemplateEnabled = r.isEmrCustomTemplateEnabled
    }
    o = function() {
        i.close(t.newDiseaseItem)
    };
    s = function() {
            i.close(t.newEMRTemplate)
        },
        function() {
            t.cancel = h;
            t.showType = e;
            t.itemData = f;
            t.parentNode = r.parentNode;
            t.saveDiseaseItem = o;
            t.saveEmrTemplate = s
        }()
}]);
orthdonticModule.controller("OrthdonticTemplateConfigDirectoryMoveCtrl", ["$log", "$scope", "$http", "$state", "$modalInstance", "aresDialog", "patientSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var h = function() {
            u.dismiss("cancel")
        },
        c = o.currentEmrTemplate,
        s = o.treeControl,
        l = s.getTree(),
        a = o.templateType,
        v = o.diseaseItemName,
        y = {
            showActionBar: !1,
            showLeafs: !1
        },
        p = function(n) {
            e.moveEMRTemplate(n).success(function(n) {
                u.close(n)
            })
        };
    (function() {
        t.currentEmrTemplate = c;
        t.treeControl = s;
        t.treeData = l;
        t.treeOpts = y;
        t.templateType = a;
        t.diseaseItemName = v;
        t.moveTemplate = p;
        t.cancel = h
    })()
}]);
orthdonticModule.controller("OrthdonticTemplateItemsettingCategoryCtrl", ["$log", "$scope", "$location", "$http", "$modalInstance", "aresDialog", "$state", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "aresNotification", "host", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    var w = function() {
            u.dismiss("cancel")
        },
        b = function() {
            h.updateEMRTemplateItemSubType(t.mainType).success(function(n) {
                y.success("保存成功！");
                u.close(n)
            }).error(function(n) {
                n.name == "SystemSettingItemNameNotUniqueException" && f.warn("警告", "已经有类目使用此名称，请更换新名称！")
            })
        };
    (function() {
        t.mainType = p;
        t.cancel = w;
        t.saveEmrtemplageItemSetting = b
    })()
}]);
orthdonticModule.controller("OrthdonticXrayAnalysisCtrl", ["$scope", "$timeout", "$state", "$q", "$log", "$filter", "$modal", "$stateParams", "orthoSvc", "dataDicSvc", "patientSvc", "appointmentSvc", "constants", "imagingSvc", "enums", "patientDocumentSvc", "loginContext", "aresDialog", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k) {
    "use strict";

    function ut() {
        var t = {
                patientId: n.patientId,
                endTime: moment(Ares.today()).add(1, "d").format(a.dateFormat),
                cancel: !1,
                isPending: !1
            },
            i = h.officeDic.data();
        angular.forEach(n.examImages, function(n) {
            n.type = "preview"
        });
        l.searchAppointmentsByTenant(t).success(function(t) {
            var i, u, r;
            for (n.appointmentsList = t, i = 0; i < n.appointmentsList.length; ++i) u = ht(n.appointmentsList[i].officeId), n.appointmentsList[i].appointmentDescription = st(n.appointmentsList[i].startTime) + " " + u, n.examImages.length > 0 && (r = _.filter(n.examImages, function(t) {
                return t.appointmentId == n.appointmentsList[i].id
            }), n.appointmentsList[i].previewImageList = r, n.appointmentsList[i].allImageList = r)
        })
    }

    function ai() {
        d = e.open({
            animation: !0,
            backdrop: "static",
            template: "<image-upload-view><\/image-upload-view>",
            controller: "ImageUploadlCtrl",
            windowClass: ".image-upload-dialog",
            size: "lg",
            resolve: {
                host: function() {
                    return {
                        imageUploadDialog: d
                    }
                }
            }
        });
        setTimeout(function() {
            $(".close").hide()
        }, 200)
    }

    function ot(t) {
        var r, i;
        if (n.appointmentsList) {
            for (r = [], i = 0; i < n.appointmentsList.length; ++i) n.appointmentsList[i].isCancelled || r.push(n.appointmentsList[i]);
            et = e.open({
                animation: !0,
                backdrop: "static",
                template: "<image-select-appointment><\/image-select-appointment>",
                controller: "ImageAppointmentsCtrl",
                windowClass: "image-appointments-select-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            appointmentsList: r,
                            callback: ii,
                            categoryType: n.categoryType,
                            usedFor: "orth",
                            image: t
                        }
                    }
                }
            })
        }
    }
    var st = f("toDateTimeString"),
        bi = f("toFirstVisit"),
        ht = f("toOfficeAbbr"),
        d = null,
        et = null,
        nt = 0,
        g = 0;
    n.currentImageList;
    n.progressBarPercentage = "0%";
    n.allImageList;
    n.categoryType = null;
    var ct = 310 / 150,
        lt = 126 / 150,
        it = function() {
            s.getPatientXRayFields(n.patientId).success(function(t) {
                n.patientExamResults = t;
                h.orthoXRayFieldDic.load().then(function(t) {
                    t && (n.categories = _.filter(angular.copy(t), function(n) {
                        return n.name !== "Downs"
                    }))
                })
            })
        },
        at = function(n) {
            n.position === 0 ? n.isWidthLarger = n.width / n.height >= ct : n.position === 1 && (n.isWidthLarger = n.width / n.height >= lt)
        },
        tt = function(n) {
            return [{
                id: 0,
                position: 0,
                title: "上传全口曲面断层片",
                inputId: "imageUploadPanel" + n + "0",
                orthoImageType: n === 0 ? 0 : 1,
                seqNum: n
            }, {
                id: 0,
                position: 1,
                title: "上传头颅侧位片",
                inputId: "imageUploadPanel" + n + "1",
                orthoImageType: n === 0 ? 0 : 1,
                seqNum: n
            }]
        },
        rt = function() {
            var t = r.defer();
            return s.getPatientXrayImages(n.patientId).success(function(i) {
                var u, r;
                if (n.xrayImages = [], n.examImages = [], _.each(i, function(t) {
                        var r, i;
                        t.image && n.examImages.push(t.image);
                        r = typeof t.seqNum == "number" ? t.seqNum : t.imageType;
                        n.xrayImages[r] = n.xrayImages[r] || tt(r);
                        i = t.image;
                        i.position = t.position;
                        i.imageDateString = pt(t.imageDate);
                        i.inputId = "imageUploadPanel" + r + i.position;
                        i.orthoImageType = r === 0 ? 0 : 1;
                        at(i);
                        n.xrayImages[r][i.position] = i
                    }), n.xrayImages.length === 0) n.xrayImages.push(tt(0));
                else
                    for (u = _.max(Object.keys(n.xrayImages)), r = u; r > 0; --r) n.xrayImages[r - 1] || (n.xrayImages[r - 1] = tt(r - 1));
                t.resolve(!0)
            }), t.promise
        },
        vt = function() {
            var t = n.xrayImages[n.xrayImages.length - 1];
            return n.xrayImages.length < 5 && (t[0].id !== 0 || t[1].id !== 0)
        },
        yt = function() {
            var t = n.xrayImages.length;
            if (t > 5) {
                k.error("最多只能添加5次X光片分析");
                return
            }
            n.xrayImages.push(tt(t))
        },
        pt = function(n) {
            return n ? moment(n).format("YYYY-MM-DD") : null
        },
        wt = function() {
            n.isEditMode = n.isEditMode ? !1 : !0
        },
        bt = function() {
            n.isEditMode = !1;
            it()
        },
        kt = function() {
            for (var i, c, r, u, l, f, e, o, a, v, h = [], t = 0; t < n.xrayImages.length; t++) h.push({
                seqNum: t,
                fields: []
            });
            for (i = !0, c = Object.keys(n.currentXrayData), t = 0; t < c.length; t++) {
                if (!i) break;
                if (r = n.currentXrayData[c[t]], u = r.xrayValues, u)
                    for (l = Object.keys(u), f = 0; f < l.length; f++)
                        if (e = l[f], o = u[e], o !== "") {
                            if (a = dt(o), !a) {
                                i = !1;
                                break
                            }
                            v = {
                                fieldId: r.id,
                                fieldName: r.name,
                                value: o,
                                seqNum: e,
                                fieldType: 2
                            };
                            h[e].fields.push(v)
                        }
            }
            if (!i) {
                n.showErrorNotification("保存失败,请输入数字");
                return
            }
            s.editPatientXRayExamFields(h, n.patientId, n.category.id).success(function() {
                n.isEditMode = !1;
                n.showNotification("保存成功！");
                it()
            })
        },
        dt = function(n) {
            if (gt(n)) return !0;
            return /^[-]{0,1}(\d+)[\.]+(\d+)$/.test(n) ? !0 : !1
        },
        gt = function(n) {
            return /^[-]{0,1}[0-9]{1,}$/.test(n)
        };
    var ni = function() {
            return "/app/orthdontic/views/orthdontic-image-upload.html"
        },
        ki = function() {
            return "/app/orthdontic/views/orthdontic-image-upload.html"
        },
        ti = function(t, i) {
            if (!n.appointmentsList || n.appointmentsList.length === 0) {
                k.error("当前患者无预约记录，无法上传X光片");
                return
            }
            d = null;
            n.currentPosition = i.position;
            n.currentImageType = i.orthoImageType;
            n.currentSeqNum = i.seqNum;
            $("#imageAppointmentDialog").css("display") !== "block" && ot(i)
        },
        ii = function(t, i, r) {
            d = null;
            n.currentAppointmentId = t;
            n.categoryId = i;
            $("#" + r.inputId).click()
        },
        ri = function(t, i) {
            if ($(t.delegatedEvent.target).attr("id") == null) {
                if ($(t.delegatedEvent.target).parent().parent().attr("appointment-id") == null) return;
                n.categoryId == null && (n.categoryId = 9)
            }
            et = null;
            d == null && ai();
            nt++;
            var r = w.apiToken,
                u = w.tokenType,
                f = {
                    appointmentId: n.currentAppointmentId,
                    categoryId: n.categoryId,
                    position: n.currentPosition,
                    type: n.currentImageType,
                    seqNum: n.currentSeqNum
                };
            i.url = w.apiHost + "/api/v1/ortho-field/upload?" + $.param(f);
            i.headers = i.headers || {};
            i.headers.Authorization = u + " " + r;
            i.submit();
            n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable")
        },
        ui = function() {},
        fi = function() {},
        ei = function(n, t) {
            $("#image-upload-current").text("当前文件: " + t.files[0].name);
            $("#image-upload-all").text("已上传:" + g + "/" + (nt + g));
            var i = parseInt(t.loaded / t.total * 99, 10);
            $("#image-upload-current-percent").css("width", i + "%")
        },
        oi = function() {
            nt--;
            g++;
            $("#image-upload-all").text("已上传:" + g + "/" + (nt + g));
            var t = parseInt(g / (nt + g) * 99, 10);
            $("#image-upload-all-percent").css("width", t + "%");
            nt == 0 && ($(".close").show(), n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable"), $(".image-upload-finish").show(), g = 0, setTimeout(function() {
                d != null && (d.dismiss("close"), $(".close").click(), d = null)
            }, 3e3));
            rt().then(function() {
                ut()
            })
        },
        si = function() {
            d.dismiss("close");
            $(".close").show();
            d = null;
            nt = 0;
            g = 0;
            b.error("错误", "文件上传失败！");
            n.categoryId == -1 ? $("#fileUploadPanel").fileupload("enable") : $("#orthoImageUploadPanel").fileupload("enable")
        },
        hi = function(n) {
            ot(n)
        },
        ci = function(n) {
            b.confirm("确认", "确定删除此影像？").then(function() {
                s.deletePatientXrayImage(n).success(function() {
                    rt().then(function() {
                        ut()
                    })
                }).error(function(n) {
                    u.error(n);
                    alert(n)
                })
            })
        },
        li = function(n) {
            Ares.download(n.mediumSizeImageUrl)
        };
    var vi = function(t) {
            var r, i, u;
            if ($(event.target).parent().parent().parent().hasClass("noclick")) {
                $(event.target).parent().parent().parent().removeClass("noclick");
                return
            }
            for (i = 0; i < n.appointmentsList.length; ++i) n.appointmentsList[i].id == t.appointmentId && (r = n.appointmentsList[i].previewImageList);
            u = e.open({
                animation: !0,
                backdrop: "static",
                template: "<image-detail-view><\/image-detail-view>",
                controller: "ImageDetailCtrl",
                windowClass: "image-detail-dialog",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            image: t,
                            allImages: r,
                            patient: n.patient
                        }
                    }
                }
            })
        },
        yi = function(t) {
            _.each(t, function(t) {
                var u = t.data[0],
                    e = t.categoryId,
                    o = u.fields,
                    f = u.seqNum,
                    i = _.findIndex(n.patientExamResults, function(n) {
                        return n.categoryId === e
                    }),
                    r = _.findIndex(n.patientExamResults[i].data, function(n) {
                        return n.seqNum === f
                    });
                r < 0 && (n.patientExamResults[i].data.push({
                    seqNum: f,
                    fields: []
                }), r = n.patientExamResults[i].data.length - 1);
                n.patientExamResults[i].data[r].fields = o
            })
        },
        pi = function(t) {
            var i, r;
            if ($(event.target).parent().parent().parent().hasClass("noclick")) {
                $(event.target).parent().parent().parent().removeClass("noclick");
                return
            }
            if (i = n.xrayImages[t], !i[1].fullImageUrl) {
                k.error("头颅侧位片未上传");
                return
            }
            r = e.open({
                animation: !0,
                backdrop: "static",
                template: "<orthdontic-ezcloud-view><\/orthdontic-ezcloud-view>",
                controller: "OrthdonticEzcloudCtrl",
                windowClass: "image-detail-dialog",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            patientId: n.patientId,
                            seqNum: t
                        }
                    }
                }
            });
            r.result.then(function() {
                s.loadEzcloudCephalometricReport(n.patientId, t).success(function(t) {
                    n.isEditMode = !1;
                    n.showNotification("保存成功！");
                    yi(t);
                    ft()
                });
                console.log("called $modalInstance.close()")
            }, function() {
                console.log("called $modalInstance.dismiss()")
            })
        },
        wi = function(t) {
            n.category = t;
            ft()
        },
        ft = function() {
            var t, i, r;
            n.isEditMode = !1;
            t = {};
            _.each(n.category.orthoFields, function(n) {
                t[n.id] = n
            });
            i = _.find(n.patientExamResults, function(t) {
                return t.categoryId === n.category.id
            });
            i && (r = i.data, _.each(r, function(n) {
                var i = n.seqNum,
                    r = n.fields;
                _.each(r, function(n) {
                    t[n.fieldId].xrayValues = t[n.fieldId].xrayValues || [];
                    t[n.fieldId].xrayValues[i] = n.value
                })
            }));
            n.currentXrayData = t
        };
    (function() {
        n.isEditMode = !1;
        n.patientId = o.patientId;
        n.constructCurrentXrayData = ft;
        n.switchCategory = wi;
        n.allowEdit = wt;
        n.cancel = bt;
        n.save = kt;
        n.openEzCloud = pi;
        n.openImage = vi;
        it();
        n.onClickFileDialog = ti;
        n.uploadStart = ui;
        n.uploadStop = fi;
        n.uploadProgressed = ei;
        n.uploadFinished = oi;
        n.uploadFailed = si;
        n.addUpload = ri;
        n.onClickDeleteImage = ci;
        n.onChangeImage = hi;
        n.categoryType = 0;
        n.onDownloadImage = li;
        n.buildImageTemplateUrl = ni;
        n.addNewXrayImageSet = yt;
        n.isNewXrayAvailable = vt;
        rt().then(function() {
            ut()
        });
        c.getPatientLiteInfo(n.patientId, !0).success(function(t) {
            n.patient = t
        })
    })()
}]);
orthdonticModule.directive("orthdonticEditTemplateChoiceView", ["$log", "$timeout", "$filter", function() {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-edit-template-choice-view.html",
        link: function(n) {
            var t = function() {
                    n.closeTemplateData()
                },
                i = function() {
                    n.saveTemplateData()
                },
                r = function(t) {
                    n.currentEmrTemplate = t;
                    n.showSaveBtn = !0;
                    event.stopPropagation()
                };
            (function() {
                n.close = t;
                n.saveTemplate = i;
                n.showSelected = r;
                n.showSaveBtn = !1;
                n.expandedNodes = []
            })()
        }
    }
}]);
clinicalModule.directive("orthdonticExaminationPrintView", ["$log", "$timeout", "$location", "$q", "enums", "patientSvc", "generalExamSvc", "officeSvc", "dataDicSvc", "loginContext", "aresDialog", "orthoSvc", "practiceSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-examination-print-view.html",
        scope: {
            patientId: "@"
        },
        link: function(n, e) {
            function g(n, t) {
                return n.position - t.position
            }
            var c = !1,
                o = !1,
                v = !1,
                y = 0,
                tt = 10,
                p = [];
            n.fieldIdList = [];
            n.rootList = [];
            var it = 150 / 97.5,
                rt = 120 / 154,
                ut = function() {
                    var t = r.defer();
                    return a.getTemplateByCode("A4OrthdonticShanDaTemplate1").success(function(i) {
                        i ? (n.isPublicTemplate = !1, l.getPatientExamFields(n.patientId).success(function(i) {
                            console.log("patientExamFields:", i);
                            n.patientExamFields = i;
                            s.orthoExamineFieldDic.load().then(function(i) {
                                var r, u;
                                i && (r = angular.copy(i), r && r.length > 0 && (r[0].active = !0), u = ft(r), n.newCommonExamFields = u[0], n.otherExamFields = u.slice(1), console.log("fields:", r), o = !0, t.resolve(!0))
                            })
                        })) : (n.isPublicTemplate = !0, l.getPatientExamFields(n.patientId).success(function(i) {
                            console.log("patientExamFields:", i);
                            n.patientExamFields = i;
                            s.orthoExamineFieldDic.load().then(function(i) {
                                if (i) {
                                    var r = angular.copy(i);
                                    r && r.length > 0 && (r[0].active = !0);
                                    et(r);
                                    n.fields = r;
                                    console.log("fields:", r);
                                    o = !0;
                                    t.resolve(!0)
                                }
                            })
                        }))
                    }), t.promise
                },
                w = function(t) {
                    var i = _.find(n.patientExamFields, function(n) {
                            return n.fieldId == t.id
                        }),
                        r;
                    return t.defaultValue ? i && (i.defaultValue = t.defaultValue) : (r = t.value, i && r && (i.defaultValue = r.split("|"))), i
                },
                ft = function(t) {
                    for (var p, w, k, ot, tt, it, l, e, rt, r, o, a, ut, s, v, y, ft, c, f, g, nt, et, u = [], i = 0; i < t.length; i++) p = d(t[i]), p && (p.isEditMode = !1, u.push(p));
                    if (n.patientExamFields) {
                        for (w = [], i = n.patientExamFields.length - 1; i >= 0; i--) k = n.patientExamFields[i].fieldId, w.push(k), n.rootList.push(n.patientExamFields[i].rootParentId), n.patientExamFields[i].field != null && (k = n.patientExamFields[i].field.parentId, w.push(k));
                        n.fieldIdList = w
                    }
                    if (u)
                        for (r = 0; r < u.length; r++)
                            for (u[r].isEditMode = !0, ot = _.find(n.rootList, function(n) {
                                    return n == u[r].id
                                }), i = 0; i < u[r].orthoFields.length; i++) ot ? (tt = _.find(n.fieldIdList, function(n) {
                                return n == u[r].orthoFields[i].id
                            }), u[r].orthoFields[i].isHideBtn = tt != null && tt != undefined ? !0 : !1) : u[r].orthoFields[i].isHideBtn = !0;
                    for (it = [], i = 0; i < u.length; i++) {
                        if (l = {}, l.name = u[i].name, l.value = u[i].value, u[i].orthoFields)
                            for (e = u[i].orthoFields, rt = [], r = 0; r < e.length; r++) {
                                if (o = {}, o.name = e[r].name, o.value = e[r].value, e[r].orthoFields)
                                    for (a = e[r].orthoFields, ut = [], s = 0; s < a.length; s++) {
                                        if (v = a[s].name, y = v.split("："), y.length > 0)
                                            for (ft = [], c = 0; c < y.length; c++) f = {}, g = y[c], f.name = g.indexOf("牙合") >= 0 ? g.replace(/牙合/, "𬌗") : g, f.index = c, f.origin = v.indexOf("牙合") >= 0 ? v.replace(/牙合/, "𬌗") : v, c == y.length - 1 ? (nt = a[s].value, f.value = nt.indexOf("牙合") >= 0 ? nt.replace(/牙合/, "𬌗") : nt) : f.value = "", f.desc = a[s].desc, ft.push(f);
                                        ut.push(ft)
                                    }
                                et = [];
                                b(ut, et);
                                o.orthoFields = et;
                                h(o);
                                rt.push(o)
                            }
                        l.orthoFields = rt;
                        it.push(l)
                    }
                    return it
                },
                b = function(n, t) {
                    var u, i, r;
                    if (t) {
                        if (u = [], t.length == 0)
                            for (i = 0; i < n.length; i++) n[i].length > 0 && u.indexOf(n[i][0].name) < 0 && (t.push(n[i][0]), u.push(n[i][0].name));
                        for (i = 0; i < t.length; i++) {
                            for (u = [], r = 0; r < n.length; r++) n[r].length > t[i].index && n[r][t[i].index].name == t[i].name && n[r].length > t[i].index + 1 && u.indexOf(n[r][t[i].index + 1].name) < 0 && (u.push(n[r][t[i].index + 1].name), t[i].orthoFields ? t[i].orthoFields.push(n[r][t[i].index + 1]) : (t[i].orthoFields = [], t[i].orthoFields.push(n[r][t[i].index + 1])));
                            b(n, t[i].orthoFields)
                        }
                        return
                    }
                },
                h = function(n, t) {
                    var u, e, i, r, f;
                    if (n.orthoFields) {
                        for (u = [], e = [], i = 0; i < n.orthoFields.length; i++) r = "", r = t ? t + "：" + n.orthoFields[i].name : n.orthoFields[i].name, n.orthoFields[i].origin ? n.orthoFields[i].origin.indexOf(r) >= 0 ? e.indexOf(r) >= 0 ? u.push(i) : (h(n.orthoFields[i], r), e.push(r)) : u.push(i) : h(n.orthoFields[i], r);
                        for (f = u.length - 1; f >= 0; f--) n.orthoFields.splice(u[f], 1);
                        return
                    }
                    return
                },
                et = function(t) {
                    for (var f, e, o, u, h, s, r = [], i = 0; i < t.length; i++) f = d(t[i]), f && (f.isEditMode = !1, r.push(f));
                    if (n.patientExamFields) {
                        for (e = [], i = n.patientExamFields.length - 1; i >= 0; i--) o = n.patientExamFields[i].fieldId, e.push(o), n.rootList.push(n.patientExamFields[i].rootParentId), n.patientExamFields[i].field != null && (o = n.patientExamFields[i].field.parentId, e.push(o));
                        n.fieldIdList = e
                    }
                    if (r)
                        for (u = 0; u < r.length; u++)
                            for (r[u].isEditMode = !0, h = _.find(n.rootList, function(n) {
                                    return n == r[u].id
                                }), i = 0; i < r[u].orthoFields.length; i++) h ? (s = _.find(n.fieldIdList, function(n) {
                                return n == r[u].orthoFields[i].id
                            }), r[u].orthoFields[i].isHideBtn = s != null && s != undefined ? !0 : !1) : r[u].orthoFields[i].isHideBtn = !0;
                    n.patientNewExamFields = r;
                    console.log("patientNewExamFields:", r)
                },
                k = function(n) {
                    n.orthoImageType == u.OrthoImageType.Denture ? n.isWidthLarger = n.width / n.height >= it : n.orthoImageType == u.OrthoImageType.Jaw && (n.isWidthLarger = n.width / n.height >= rt)
                },
                d = function(n) {
                    for (var i, t, f, r, u = 0; u < n.orthoFields.length; u++)
                        for (i = n.orthoFields[u], i.isHideBtn = !1, t = w(i), t && t.value && (i.isHideBtn = !0, i.defaultValue = t.defaultValue, i.value = t.value, i.examFieldId = t.id), f = 0; f < i.orthoFields.length; f++) r = i.orthoFields[f], t = w(r), t && t.value ? (i.isHideBtn = !0, r.defaultValue = t.defaultValue, r.value = t.value, r.examFieldId = t.id) : r.value && (r.defaultValue = r.value.split("|"), r.value = "");
                    return n
                },
                ot = function() {
                    var t = r.defer();
                    return f.getPatient(n.patientId).success(function(i) {
                        n.patient = i;
                        n.sexCodeValue = i.sex === 1 ? "男" : i.sex === 0 ? "未知" : "女";
                        n.birthday = i.birth ? moment(i.birth).format("YYYY年MM月DD日") : "";
                        n.familyAddress = "";
                        i.familyAddress && (i.familyAddress.province && i.familyAddress.province !== "XX" && (n.familyAddress += i.familyAddress.province), i.familyAddress.city && i.familyAddress.city !== "内网IP" && (n.familyAddress += i.familyAddress.city), i.familyAddress.district && i.familyAddress.district !== "内网IP" && (n.familyAddress += i.familyAddress.district), i.familyAddress.content && (n.familyAddress += i.familyAddress.content));
                        v = !0;
                        t.resolve(!0)
                    }), t.promise
                };
            var st = function() {
                    var t = r.defer();
                    return l.getPatientExamineImages(n.patientId).success(function(i) {
                        var f, r;
                        for (n.dentureImage = [], n.jawImage = [], r = 0; r < i.length; r++) f = i[r].image, f.position = i[r].position, f.imageDate = i[r].imageDate, f.inputId = "imageUploadPanel" + f.position + i[r].imageType, i[r].imageType == u.OrthoImageType.Denture && (f.orthoImageType = u.OrthoImageType.Denture, k(f), n.dentureImage.push(f)), i[r].imageType == u.OrthoImageType.Jaw && (f.orthoImageType = u.OrthoImageType.Jaw, k(f), n.jawImage.push(f)), p.push(f);
                        for (r = 0; r < 7; r++) ht(n.dentureImage, r);
                        for (r = 0; r < 6; r++) ct(n.jawImage, r);
                        n.dentureImage.sort(g);
                        n.jawImage.sort(g);
                        c = !0;
                        t.resolve(!0)
                    }), t.promise
                },
                ht = function(n, t) {
                    var i = _.find(n, function(n) {
                        return n.position == t
                    });
                    if (!i) switch (t) {
                        case 0:
                            n.push({
                                id: 0,
                                position: t,
                                title: "正位像",
                                inputId: "imageUploadPanel" + t + "2"
                            });
                            break;
                        case 1:
                            n.push({
                                id: 0,
                                position: t,
                                title: "上牙列",
                                inputId: "imageUploadPanel" + t + "2"
                            });
                            break;
                        case 2:
                            n.push({
                                id: 0,
                                position: t,
                                title: "左侧咬合",
                                inputId: "imageUploadPanel" + t + "2"
                            });
                            break;
                        case 3:
                            n.push({
                                id: 0,
                                position: t,
                                title: "前牙覆牙合覆盖",
                                inputId: "imageUploadPanel" + t + "2"
                            });
                            break;
                        case 4:
                            n.push({
                                id: 0,
                                position: t,
                                title: "下牙列",
                                inputId: "imageUploadPanel" + t + "2"
                            });
                            break;
                        case 5:
                            n.push({
                                id: 0,
                                position: t,
                                title: "右侧咬合",
                                inputId: "imageUploadPanel" + t + "2"
                            })
                    }
                },
                ct = function(n, t) {
                    var i = _.find(n, function(n) {
                        return n.position == t
                    });
                    if (!i) switch (t) {
                        case 0:
                            n.push({
                                id: 0,
                                position: t,
                                title: "正面",
                                inputId: "imageUploadPanel" + t + "3"
                            });
                            break;
                        case 1:
                            n.push({
                                id: 0,
                                position: t,
                                title: "正面微笑",
                                inputId: "imageUploadPanel" + t + "3"
                            });
                            break;
                        case 2:
                            n.push({
                                id: 0,
                                position: t,
                                title: "侧位像",
                                inputId: "imageUploadPanel" + t + "3"
                            });
                            break;
                        case 3:
                            n.push({
                                id: 0,
                                position: t,
                                title: "右侧面45度",
                                inputId: "imageUploadPanel" + t + "3"
                            });
                            break;
                        case 4:
                            n.push({
                                id: 0,
                                position: t,
                                title: "左侧面45度",
                                inputId: "imageUploadPanel" + t + "3"
                            })
                    }
                },
                lt = function() {
                    var t = i.search();
                    n.param = t;
                    n.patientId = t.patientId
                },
                nt = function nt(n) {
                    t(function() {
                        v && c && o ? at(n) : (y++, y > tt ? n && n(!1) : nt(n))
                    }, 1e3)
                },
                at = function(n) {
                    var i = e.find("#imgContainer");
                    angular.forEach(p, function(n) {
                        var t = '<img style="width:50px;" src="' + n.thumbnailUrl + '" />';
                        i.append(t)
                    });
                    i.waitForImages(function() {
                        t(function() {
                            window.print();
                            n && n(!0)
                        }, 100)
                    })
                };
            (function() {
                lt();
                ut().then(function() {
                    st().then(function() {
                        ot()
                    })
                });
                window.printEx = nt
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticExaminationView", ["$log", "$timeout", "$state", "$stateParams", function() {
    "use strict";
    return {
        restrict: "E",
        controller: "OrthdonticExaminationCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-examination-view.html",
        link: function() {}
    }
}]);
orthdonticModule.directive("orthdonticEzcloudView", ["$log", "$timeout", "$state", "$stateParams", "orthoSvc", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-ezcloud-view.html",
        link: function(n, t) {
            (function() {
                var r = $(window).width(),
                    i = $(window).height(),
                    f = i - 20,
                    e = r.toString().concat("*", i.toString());
                u.getEzcloudWorkspaceUrl(n.patientId, n.seqNum, e).then(function(n) {
                    t.find("#framediv").append('<iframe id="ezwindow" name="ezwindow" style="height:620px;width:100%;" src="' + n.data + '"><\/iframe>');
                    var i = window.frames.ezwindow;
                    $("#ezwindow").css("height", f.toString().concat("px"))
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticFileView", ["$log", "$timeout", "appointmentSvc", "patientSvc", "messengerSvc", "practiceSvc", "loginContext", "$modal", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        controller: "OrthdonticFileCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-file-view.html",
        link: function(n) {
            (function() {
                r.getLitePatient(n.patientId).success(function(t) {
                    n.patient = t
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticHomeView", ["$log", "appNav", "$state", "$stateParams", "orthoSvc", "enums", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-home-view.html",
        link: function(n) {
            var e = function(i) {
                    n.selectMenu != i && (n.selectMenu = i, t.switchState("patientOrthdontic." + i, {
                        patientId: r.patientId,
                        orthStateName: i
                    }))
                },
                o = function() {
                    if (n.stateName) {
                        n.selectMenu = n.stateName;
                        return
                    }
                    u.getPatientOrthoStateByPatientId(n.patientId).success(function(i) {
                        n.selectMenu = i == f.OrthoState.Examine ? "examination" : i == f.OrthoState.Plan ? "plan" : i == f.OrthoState.Process ? "process" : "examination";
                        t.switchState("patientOrthdontic." + n.selectMenu, {
                            patientId: r.patientId
                        })
                    })
                };
            (function() {
                n.onSelected = e;
                n.stateName = i.params.orthStateName;
                o()
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticPlanView", ["$log", "$timeout", "$state", "$stateParams", "$sce", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        controller: "OrthdonticPlanCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-plan-view.html",
        link: function(n, t) {
            var r = function(t) {
                    n.pageState = t
                },
                f = function() {
                    n.allEditBtnState = !1;
                    n.isFieldEdit = !0
                },
                e = function() {
                    n.editExamNotes = angular.copy(n.editExamNotesSnapshoot);
                    n.allEditBtnState = !0;
                    n.isFieldEdit = !1
                },
                o = function() {
                    n.isFieldEdit = !n.isFieldEdit;
                    n.allEditBtnState = !1
                },
                s = function() {
                    n.isFieldEdit = !n.isFieldEdit;
                    n.allEditBtnState = !0
                },
                h = function() {
                    n.pageState = "view";
                    n.isFieldEdit = !1;
                    n.isPlanEdit = !1
                },
                c = function() {
                    var t = n.editExamNotes.length;
                    n.editExamNotes.push({
                        seqNum: t + 1
                    })
                },
                l = function(t) {
                    n.editExamNotes = _.filter(n.editExamNotes, function(n) {
                        return n.seqNum !== t
                    });
                    for (var i = 0; i < n.editExamNotes.length; i++) n.editExamNotes[i].seqNum = i + 1
                },
                a = function(t, i) {
                    i || (i = {});
                    _.each(n.agreementTemplates, function(n) {
                        n.isChecked = n.id === t.id
                    });
                    i.agreementTemplateId = t && t.isChecked ? t.id : null
                },
                v = function(t) {
                    Array.isArray(t) ? _.forEach(t, function(t) {
                        i(t);
                        _.isArray(n.agreementTemplates) && _.forEach(n.agreementTemplates, function(n) {
                            n.isChecked = n.id === t.agreementTemplateId
                        })
                    }) : (i(t), _.isArray(n.agreementTemplates) && _.forEach(n.agreementTemplates, function(n) {
                        n.isChecked = n.id === t.agreementTemplateId
                    }))
                },
                i = function(i) {
                    n.selectedTemplate = i ? _.find(n.agreementTemplates, {
                        id: i.agreementTemplateId
                    }) : null;
                    n.selectedTemplate && n.selectedTemplate.content ? (t.find("#agreementTemplatePrint").html(u.trustAsHtml(n.selectedTemplate.content).toString()), t.find("#agreementTemplateTitle").show(), t.find("#agreementTemplatePrint").show()) : (t.find("#agreementTemplatePrint").html(""), t.find("#agreementTemplateTitle").hide(), t.find("#agreementTemplatePrint").hide())
                },
                y = function(n, t) {
                    t.splice(n, 1)
                },
                p = function(n) {
                    n.isEdit = !1;
                    n.editName = ""
                },
                w = function(n) {
                    n.isEdit = !1;
                    n.name = angular.copy(n.editName)
                },
                b = function(n) {
                    n.isEdit = !0;
                    n.editName = angular.copy(n.name)
                },
                k = function(n, t) {
                    if (n) {
                        var i = {
                            name: n.addText,
                            code: null,
                            pinyin: null,
                            isNew: 1
                        };
                        i.name && (t.push(i), n.addText = "")
                    }
                },
                d = function(n, t) {
                    var i = {
                        code: n.code,
                        id: n.id,
                        name: n.name,
                        isNew: 0
                    };
                    t.push(i)
                },
                g = function(n, t) {
                    if (n !== 0) {
                        var i = t[n];
                        t.splice(n, 1);
                        t.splice(n - 1, 0, i)
                    }
                },
                nt = function(n, t) {
                    if (n !== t.length - 1) {
                        var i = t[n];
                        t.splice(n, 1);
                        t.splice(n + 1, 0, i)
                    }
                },
                tt = function() {
                    n.hasShowAddStepWrap || (n.hasShowAddStepWrap = !0)
                },
                it = function(t, i) {
                    n.hasShowAddStepWrap = !1;
                    t && i.push(t)
                },
                rt = function() {
                    n.hasShowAddStepWrap = !1
                };
            (function() {
                n.onAddRow = c;
                n.onDelRow = l;
                n.pageState = "view";
                n.changePageState = r;
                n.close = h;
                n.setOnlyOneSelect = a;
                n.getSelectAgreementTemplate = v;
                n.deleteStepItem = y;
                n.cancelStepItem = p;
                n.saveStepItem = w;
                n.upItem = g;
                n.downItem = nt;
                n.editStepItem = b;
                n.selectText = d;
                n.addSteps = k;
                n.fieldCancelState = s;
                n.fieldEditState = o;
                n.editField = f;
                n.cancelField = e;
                n.onAddStep = tt;
                n.onSure = it;
                n.onCancel = rt;
                n.hasShowAddStepWrap = !1
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticProcessEditItemChoiceView", ["$http", "$q", "$compile", "$filter", "$timeout", "patientSvc", function(n, t, i, r, u, f) {
    var e, o;
    return e = t.defer(), o = "/SublimeText3Project/yayi/json/index/lftrain.linkedcare.cn/app/orthdontic/views/orthdontic-process-edit-item-choice-view.html", u(function() {
        f.listOrthdonticTemplateTreeItems().success(function(n) {
            return e.resolve(n)
        })
    }, 300), {
        restrict: "A",
        scope: {
            ngModel: "=",
            levelNode: "=level"
        },
        link: function(t, u, f) {
            var h = u.siblings(".template-select-district"),
                c = f.orthdonticProcessEditItemChoiceView,
                s;
            return s = {
                show: function() {
                    return angular.element(".template-select-district").removeClass("active"), h.addClass("active")
                },
                hide: function() {
                    h.removeClass("active")
                },
                resize: function() {
                    if (this.element) return !1
                },
                init: function() {
                    u.on("click", function(n) {
                        return s.show(), n.stopPropagation(), !1
                    });
                    u.on("keydown", function(n) {
                        if (n.which === 27) return s.hide(), !1
                    });
                    $(window).on("click", function(n) {
                        return function() {
                            return n.hide()
                        }
                    }(this));
                    h.on("click", function(n) {
                        return n.stopPropagation()
                    });
                    return setTimeout(function(n) {
                        return function() {
                            return n.element.show(), n.resize()
                        }
                    }(this), 500)
                }
            }, e.promise.then(function(e) {
                n.get(o).success(function(n) {
                    var r, u, f;
                    return r = i(n)(t), h.append(r), s.element = $(r[2]), u = [], angular.forEach(e, function(n) {
                        n.mainType == c && (u = n.subTypes)
                    }), f = c.split("-")[1], t.mainTypeName = f, t.subTypesArray = u, s.init()
                });
                t.addContentByItem = function(n) {
                    var o = f.id,
                        i = document.getElementById(o),
                        s = 0,
                        r = 0,
                        u = 0,
                        e;
                    i.selectionStart && (s = i.selectionStart, r = i.selectionStart, u = i.selectionEnd);
                    e = i.value.substring(0, r) + n;
                    i.value = i.value.substring(0, r) + n + i.value.substring(u, i.value.length);
                    i.focus();
                    i.setSelectionRange(i.value.length, e.length);
                    t.ngModel = i.value
                };
                t.additional = function(n) {
                    t.addContentByItem(n)
                };
                t.addContent = function(n) {
                    t.addContentByItem(n)
                };
                t.getContent = function(n) {
                    var i = r("fieldsStrByOrthdonticTemplate")(c),
                        f, u;
                    t.contentItemName = n.itemName;
                    f = n;
                    u = [];
                    angular.forEach(f.childrenItems, function(n) {
                        if (n.childrenItems && n.spriteCssClass == "folder") {
                            var t = n.childrenItems;
                            angular.forEach(t, function(n) {
                                if (n.childrenItems && n.spriteCssClass == "folder") {
                                    var t = n.childrenItems;
                                    angular.forEach(t, function(n) {
                                        n[i] && u.push(n[i])
                                    })
                                } else n[i] && u.push(n[i])
                            })
                        } else n[i] && u.push(n[i])
                    });
                    !f.childrenItems && f[i] && u.push(f[i]);
                    t.contentArray = u;
                    t.clickedName = n.itemName
                };
                t.close = function() {
                    return s.hide()
                };
                t.getContentWidth = function(n) {
                    var i = n.length,
                        t = 12 * i,
                        r = u.closest("td").width() * .75 - 45,
                        f = u.closest(".medical-record-text").width() * .94 * .75 - 45;
                    return t > r || t > f ? !0 : !1
                };
                t.$watch("levelNode", function(n) {
                    if (n) {
                        var i = n[0];
                        t.getContent(i)
                    }
                })
            })
        }
    }
}]);
orthdonticModule.directive("orthdonticProcessEditView", ["$log", "$timeout", "$q", "$window", "$modal", "appNav", "loginContext", "schedulerUtil", "$sce", "systemConfigUtil", "printTemplateUtil", "constants", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "OrthdonticProcessEditCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-process-edit-view.html",
        link: function(n, r) {
            var a = null,
                v = function(t) {
                    n.printTemplateConfig = {
                        configName: "orthdontic",
                        coments: "emrPrint"
                    };
                    var r = t && t.configName == "orthdontic" ? i.when(t.configValue) : h.getConfigValue("orthdontic");
                    r.then(function(t) {
                        if (t && t != "") {
                            var i = t;
                            n.printTemplateConfig.isHide = !1;
                            n.printTemplateConfig.templateCode = i;
                            i.indexOf("Orthdontic") < 0 && (n.printTemplateConfig.isHide = !0);
                            c.getTemplateByCode(i).then(function(t) {
                                n.printTemplate = t
                            })
                        } else n.printTemplateConfig.isHide = !0;
                        b()
                    })
                },
                k = function() {
                    var n = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<emr-print-configuration-view><\/emr-print-configuration-view>",
                        controller: "emrPrintConfigurationCtrl",
                        size: "lg",
                        resolve: {
                            host: function() {
                                return {
                                    template: "orthdontic"
                                }
                            }
                        }
                    });
                    n.result.then(function(n) {
                        v(n)
                    })
                },
                d = function() {
                    var t = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-edit-template-choice-view><\/orthdontic-edit-template-choice-view>",
                        controller: "OrthdonticEditTemplateChoiceCtrl",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    treeControl: n.templateTreeControl,
                                    emrTemplates: n.emrTemplates,
                                    currentMedicalRecord: n.currentMedicalRecord
                                }
                            }
                        }
                    });
                    t.result.then(function(t) {
                        n.currentMedicalRecord = t
                    })
                },
                g = function(n) {
                    var t = r.find("#" + n + ' textarea[name="' + n + '"]');
                    t.trigger("click");
                    t.focus()
                },
                nt = function(n) {
                    n.newItem = n.newItem ? "" : n.parent
                },
                tt = function(t) {
                    f.switchState(t, {
                        patientId: n.patientId,
                        orthStateName: "process"
                    })
                },
                it = function() {
                    r.find("#doctor").kendoNameCodeFilterComboBox({
                        dataSource: n.doctors,
                        filter: "contains",
                        placeholder: "请选择医生",
                        dataTextField: "name",
                        dataValueField: "id"
                    });
                    n.currentMedicalRecord.doctorId > 0 ? s(n.currentMedicalRecord.doctorId, "doctor") : e.isDoctor && s(e.providerId, "doctor")
                },
                rt = function() {
                    r.find("#nurse").kendoNameCodeFilterComboBox({
                        dataSource: n.nurses,
                        filter: "contains",
                        placeholder: "请选择助手",
                        dataTextField: "name",
                        dataValueField: "id"
                    });
                    n.currentMedicalRecord.nurseId > 0 && s(n.currentMedicalRecord.nurseId, "nurse")
                },
                ut = function() {
                    var t = n.historyAppts,
                        i;
                    n.isCheckedInToday && !n.currentMedicalRecord.id && n.isStrongStrict && (i = Ares.today(), t = _.filter(n.historyAppts, function(n) {
                        return new Date(n.startTime) >= i && n.isCheckedIn
                    }));
                    r.find("#appoint").kendoDropDownList({
                        dataSource: t,
                        placeholder: "请选择",
                        valueTemplate: '<span class="k-state-default">#: data.startTimeStr #<\/span>',
                        template: '<span class="k-state-default">#: data.startTimeStr #<\/span>',
                        dataValueField: "id",
                        select: function(t) {
                            var i = this.dataItem(t.item.index()),
                                u;
                            y(i.id > 0 ? !1 : !0);
                            n.currentMedicalRecord.appointId = i.id;
                            n.currentMedicalRecord.appointDateTime = i.startTime;
                            n.currentMedicalRecord.doctorName = i.doctorName;
                            n.currentMedicalRecord.doctorId = i.doctorId;
                            u = r.find("#doctor").data("kendoNameCodeFilterComboBox");
                            u && u.value(i.doctorId);
                            n.$apply()
                        }
                    });
                    n.currentMedicalRecord.id > 0 && s(n.currentMedicalRecord.appointId, "appoint")
                },
                s = function(t, i, u) {
                    var f = null,
                        e;
                    if (i == "doctor" && (f = _.findIndex(n.doctors, function(n) {
                            return n.id == t
                        })), i == "appoint")
                        if (u) f = _.findIndex(u, function(n) {
                            return n.id == t
                        });
                        else if (n.isStrongStrict) {
                        var o = moment(Ares.today()).format(l.dateFormat),
                            s = moment(Ares.today()).add(1, "d").format(l.dateFormat),
                            h = n.historyAppts.filter(function(n) {
                                return n.startTime >= o && n.startTime < s && n.isCheckedIn
                            });
                        f = _.findIndex(h, function(n) {
                            return n.id == t
                        })
                    } else f = _.findIndex(n.historyAppts, function(n) {
                        return n.id == t
                    });
                    i == "nurse" && (f = _.findIndex(n.nurses, function(n) {
                        return n.id == t
                    }));
                    f >= 0 && (e = r.find("#" + i).data("kendoNameCodeFilterComboBox"), i == "appoint" && (e = r.find("#" + i).data("kendoDropDownList")), e && e.select(f))
                },
                ft = function() {
                    var t = r.find("#nurse").data("kendoNameCodeFilterComboBox");
                    t && t.select() != -1 && (n.currentMedicalRecord.nurseName = t.text(), n.currentMedicalRecord.nurseId = t.value())
                },
                et = function() {
                    var n = r.find("#doctor").data("kendoNameCodeFilterComboBox");
                    return n.select()
                },
                ot = function() {
                    var t = r.find("#doctor").data("kendoNameCodeFilterComboBox");
                    t && t.select() != -1 && (n.currentMedicalRecord.doctorName = t.text(), n.currentMedicalRecord.doctorId = t.value())
                },
                p = function(n) {
                    return n != null && (_.each(n.oralCheckRecordList, function(n) {
                        n != null && n.fdiToothCodesArray != null && (n.description = n.fdiToothCodesArray.join(",") + n.description)
                    }), _.each(n.cureRecordList, function(n) {
                        n != null && n.fdiToothCodesArray != null && (n.cure = n.fdiToothCodesArray.join(",") + n.cure)
                    }), _.each(n.treatmentAdviceList, function(n) {
                        n != null && n.fdiToothCodesArray != null && (n.content = n.fdiToothCodesArray.join(",") + n.content)
                    }), n.oralCheckRecordList = _.pluck(n.oralCheckRecordList, "description").join("|"), n.cureRecordList = _.pluck(n.cureRecordList, "cure").join("|"), n.treatmentAdviceList = _.pluck(n.treatmentAdviceList, "content").join("|"), n.nurseId || (n.nurseId = "0")), _.pick(n, "oralCheckRecordList", "cureRecordList", "treatmentAdviceList", "doctorId", "nurseId")
                },
                st = function(t, i) {
                    var u = r.find("#appoint").data("kendoDropDownList");
                    u != null && (i ? u.dataSource.data(i) : u.dataSource.data(n.historyAppts), s(t.id, "appoint", i), i || s(t.doctorId, "doctor"))
                },
                ht = function() {
                    var i = w(),
                        u = moment(i.value()).format("HH:mm"),
                        f = moment(i.value()).add(30, "m").format("HH:mm"),
                        e = n.tempHistoryAppts || n.historyAppts,
                        t = _.find(e, {
                            id: -2
                        }),
                        o;
                    t && (t.startTime = moment(t.startTime).format("YYYY-MM-DD " + u), t.startTimeStr = moment(t.startTime).format("YYYY年MM月DD日 " + u), t.endTime = moment(t.endTime).format("YYYY-MM-DD " + f), t.endTimeStr = moment(t.endTime).format("YYYY年MM月DD日 " + f), o = r.find("#appoint").data("kendoDropDownList"), o.dataSource.data(e))
                },
                y = function(n) {
                    var t = w();
                    t && t.enable(n)
                },
                w = function() {
                    return a || (a = r.find("#timepicker").data("kendoTimePicker")), a
                },
                ct = function() {
                    o.loadSchedulerConfig().then(function(t) {
                        n.timePickerOption = t && t.timeSlotUnit ? {
                            interval: t.timeSlotUnit
                        } : {
                            interval: 30
                        }
                    })
                },
                b = function() {
                    n.isdisabled = n.printTemplateConfig.isHide || n.currentMedicalRecord && n.currentMedicalRecord.id == 0 || n.currentMedicalRecord && n.currentMedicalRecord.id > 0 && n.isChanged
                },
                lt = function() {
                    ct();
                    n.isEdit && v();
                    t(function() {
                        y(!1)
                    }, 100)
                },
                at = function(t, i, r) {
                    r == 0 ? n.currentMedicalRecord.oralCheckRecordList[i].description += " " + t.name + ", " : r == 1 ? n.currentMedicalRecord.cureRecordList[i].description += " " + t.name + ", " : r == 2 && (n.currentMedicalRecord.treatmentAdviceList[i].description += " " + t.name + ", ")
                };
            (function() {
                n.isdisabled = !0;
                n.disablePrint = b;
                n.goToList = tt;
                n.selectDropDown = s;
                n.setNurse = ft;
                n.setDoctor = ot;
                n.getDoctor = et;
                n.refreshApptDropDown = st;
                n.onTimePickerChanged = ht;
                n.isEnabledTimePicker = y;
                n.onObservationSelected = at;
                n.scrollIntoView = g;
                n.changeCategory = nt;
                n.selectTemplate = d;
                n.toPrint = k;
                n.initPrint = v;
                lt();
                n.$watch("nurses", function() {
                    n.nurses && rt()
                });
                n.$watch("doctors", function() {
                    n.doctors && it()
                });
                n.$watch("historyAppts", function() {
                    n.historyAppts && ut()
                });
                n.$watch("currentMedicalRecord", function() {
                    if (n.currentMedicalRecord && n.currentMedicalRecord.id > 0 && !n.isUpdating && n.originalMedicalRecord) {
                        var t = angular.copy(n.originalMedicalRecord),
                            i = angular.copy(n.currentMedicalRecord);
                        i = p(i);
                        t = p(t);
                        n.isChanged = _.isEqual(t, i) ? !1 : !0
                    }
                }, !0)
            })()
        }
    }
}]);
emrModule.directive("orthdonticProcessTemplateCategoryChoiceView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-process-template-category-choice-view.html",
        link: function(n, i) {
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 100)
        }
    }
}]);
orthdonticModule.directive("orthdonticProcessTemplateSaveView", ["$log", "$timeout", "$q", "$modal", "loginContext", "dataDicSvc", "patientSvc", "aresDialog", "officeOptionSvc", "enums", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-process-template-save-view.html",
        link: function(n, i) {
            var f = function() {
                    if (n.currentOrthdonticTemplate.itemName = n.currentOrthdonticTemplate.templateName, n.templateTreeControl.checkDuplicateNameSibling(n.currentOrthdonticTemplate)) {
                        o.warn("提示", "该模板类别已存在同名的子目录或模板");
                        return
                    }
                    if (n.isSaving = !0, n.currentOrthdonticTemplate.diseaseId === null) {
                        o.warn("提示", "请选择模板！");
                        return
                    }
                    n.currentOrthdonticTemplate.templateType = h.TemplateType.Orthodontic;
                    e.createEMRTemplate(n.currentOrthdonticTemplate).success(function() {
                        o.info("信息", "模板保存成功！");
                        n.cancel()
                    }).error(function() {
                        o.warn("提示", "保存失败！");
                        n.isSaving = !1
                    })
                },
                s = function() {
                    var t = r.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-process-template-category-choice-view><\/orthdontic-process-template-category-choice-view>",
                        controller: "OrthdonticProcessTemplateCategoryChoiceCtrl",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    treeControl: n.templateTreeControl
                                }
                            }
                        }
                    });
                    t.result.then(function(t) {
                        n.currentOrthdonticTemplate.diseaseId = t.id;
                        n.currentOrthdonticTemplateCategoryBreadcrumb = t.breadcrumb;
                        t.departmentName === "我的模板" && (n.currentOrthdonticTemplate.userId = u.userId)
                    })
                };
            (function() {
                n.ok = f;
                n.showTemplateCategoryChoiceDlg = s;
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticProcessView", ["$log", "$timeout", "appNav", "aresDialog", "patientSvc", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "OrthdonticProcessCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-process-view.html",
        link: function(n, f) {
            var e = function(t) {
                    i.switchState(t, {
                        patientId: n.patientId,
                        orthStateName: "process"
                    })
                },
                o = function(t) {
                    t.isAllowEdit == 1 ? i.switchState("patientOrthdontic.processEdit", {
                        patientId: n.patientId,
                        recordId: t.medicalRecordId,
                        orthStateName: "process"
                    }) : t.isAllowEdit == 2 ? r.info("提醒", "该病历超出正畸时限范围，不允许修改！") : u.isAllowEditOrthdonticRecordByTimeLimit(t.medicalRecordId).success(function(u) {
                        u ? (t.isAllowEdit = 1, i.switchState("patientOrthdontic.processEdit", {
                            patientId: n.patientId,
                            recordId: t.medicalRecordId,
                            orthStateName: "process"
                        })) : (t.isAllowEdit = 2, r.info("提醒", "该病历超出正畸时限范围，不允许修改！"))
                    })
                },
                s = function(n) {
                    t(function() {
                        var t = f.find("." + n.className).height() - 38 + "px";
                        n.detailHeight = t
                    }, 300)
                },
                h = function() {
                    n.medicalRecordId > 0 && t(function() {
                        var i = "#mid" + n.medicalRecordId,
                            t = f.find(i);
                        t && t.length > 0 && t[0].scrollIntoView()
                    }, 500)
                };
            (function() {
                n.setHeight = s;
                n.editEMR = o;
                n.switchState = e;
                n.autoScroll = h
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanAgreementDialog", ["$log", "$modal", "$timeout", "dataDicSvc", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-agreement-dialog.html",
        link: function(n, t) {
            i(function() {
                Ares.centerModal(t.closest(".modal-dialog"))
            }, 5);
            var r, u = function() {
                    r = Ares.validateForm(t.find("#practiceForm"), {
                        title: {
                            required: !0
                        }
                    }, {
                        title: {
                            required: "请输入标题"
                        }
                    })
                },
                f = function() {
                    if (t.find("#practiceForm").valid()) return n.saveForm(), deferred.promise
                };
            (function() {
                n.agreementTemplate = {};
                u();
                n.save = f;
                n.$watch("agreementTemplate", function() {
                    r && Ares.clearError(t.find("#practiceForm"))
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanAgreementView", ["$log", "appNav", "$state", "$stateParams", "$modal", "$timeout", "$sce", "aresDialog", "aresNotification", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        controller: "orthdonticSettingPlanAgreementCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-agreement-view.html",
        link: function(n, t) {
            var r, i = null,
                a = function() {
                    var r = t.find("#templateList");
                    i = r.kendoGrid({
                        dataSource: {
                            data: n.agreementTemplates
                        },
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        columns: [{
                            field: "title",
                            title: "",
                            attributes: {
                                style: "text-align: left;padding-left:20px;"
                            }
                        }],
                        change: function() {
                            var i = this.dataItem(this.select());
                            if (n.isEdit) {
                                s.error("请先保存");
                                i.id != n.selectTemplate.id && h();
                                return
                            }
                            f(function() {
                                i ? (n.selectTemplate = i, n.selectTemplateContentHtml = n.selectTemplate.content ? e.trustAsHtml(n.selectTemplate.content).toString() : "", t.find("#templateContent").html(n.selectTemplateContentHtml), l(n.selectTemplate.content)) : n.selectTemplate = null
                            })
                        }
                    }).data("kendoGrid");
                    i.element.find("tbody>tr").removeClass("k-alt")
                },
                v = function() {
                    i ? (i.dataSource.data(n.agreementTemplates), i.element.find("tbody>tr").removeClass("k-alt"), h()) : a()
                },
                h = function() {
                    var u, t, r;
                    n.selectTemplate && (u = i.dataSource, t = u.get(n.selectTemplate.id), t && (r = i.element.find("tbody>tr[data-uid=" + t.uid + "]"), r && i.select(r)))
                },
                y = function() {
                    if (n.isEdit) {
                        s.error("请先保存");
                        selectTemplate.id != n.selectTemplate.id && h();
                        return
                    }
                    var t = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-setting-plan-agreement-dialog><\/orthdontic-setting-plan-agreement-dialog>",
                        controller: "orthdonticSettingPlanAgreementDialogCtrl",
                        size: "agreement"
                    });
                    t.result.then(function() {
                        n.initData()
                    })
                },
                p = function() {
                    c(!0)
                },
                w = function() {
                    c(!1)
                },
                c = function(t) {
                    if (n.selectTemplate) {
                        var i;
                        t && n.selectTemplate.displayOrder > 0 ? (i = _.find(n.agreementTemplates, {
                            displayOrder: n.selectTemplate.displayOrder - 1
                        }), n.selectTemplate.displayOrder = n.selectTemplate.displayOrder - 1, i.displayOrder = i.displayOrder + 1) : !t && n.selectTemplate.displayOrder < n.agreementTemplates.length - 1 && (i = _.find(n.agreementTemplates, {
                            displayOrder: n.selectTemplate.displayOrder + 1
                        }), n.selectTemplate.displayOrder = n.selectTemplate.displayOrder + 1, i.displayOrder = i.displayOrder - 1);
                        i && n.saveTemplateChange(i).then(function() {
                            n.saveTemplateChange(n.selectTemplate).then(function() {
                                n.initData()
                            })
                        })
                    }
                },
                b = function() {
                    n.selectTemplate && o.confirm("提示", "确定要删除此模板？").then(function() {
                        n.deleteTemplate(n.selectTemplate.id).then(function() {
                            n.initData();
                            t.find("#templateContent").html("");
                            n.selectTemplate = null
                        })
                    })
                },
                l = function(n) {
                    if (r) {
                        var i = $("#editor").data("kendoEditor");
                        i.value(n)
                    } else r = $(t).find("#editor").kendoEditor({
                        value: n,
                        encoded: !1,
                        resizable: {
                            content: !0,
                            toolbar: !0
                        }
                    })
                },
                k = function() {
                    n.selectTemplate && (n.isEdit = !0, l(n.selectTemplate.content))
                },
                d = function() {
                    n.isEdit = !1
                },
                g, nt = function() {
                    g = Ares.validateForm(t.find("#practiceForm"), {
                        title: {
                            required: !0
                        }
                    }, {
                        title: {
                            required: "请输入模板名称"
                        }
                    })
                },
                tt = function() {
                    t.find("#practiceForm").valid() && n.selectTemplate && (n.selectTemplate.content = e.trustAsHtml(r.val()).toString(), n.saveTemplateChange(n.selectTemplate).then(function() {
                        s.success("保存成功");
                        n.isEdit = !1;
                        n.initData()
                    }))
                };
            (function() {
                nt();
                n.openAddDialog = y;
                n.moveUpTemplate = p;
                n.moveDownTemplate = w;
                n.deleteSelectedTemplate = b;
                n.editTemplate = k;
                n.cancelEditTemplate = d;
                n.saveTemplate = tt;
                n.selectTemplateContentHtml = "";
                n.isEdit = !1;
                n.$watch("agreementTemplates", function() {
                    n.agreementTemplates && v()
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanDiagnosticConfigView", ["$log", "$timeout", "$window", "dataDicSvc", "orthoSvc", "officeUtil", "aresDialog", "$modal", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-diagnostic-config-view.html",
        controller: "OrthdonticSettingPlanDiagnosticConfigCtrl",
        link: function(n) {
            var t = function() {
                    return n.isEdit ? (e.warn("提示", "请先保存编辑中的内容"), !0) : !1
                },
                i = function(i) {
                    var f = t(),
                        r, u;
                    f || (n.mainTypeTabs.forEach(n => n.active = !1), i.active = !0, r = n.diagnosticConfigData.find(n => n.mainType == i.name), r && r.subTypes.length > 0 && (r.subTypes.forEach(n => n.selected = !1), u = r.subTypes[0], u.selected = !0, n.currentSubType = u), n.currentMainTypeConfig = r)
                },
                r = function(i) {
                    var u = t(),
                        r;
                    u || (n.currentMainTypeConfig.subTypes.forEach(n => n.selected = !1), i.selected = !0, r = n.mainTypeTabs.find(n => n.active), r && (n.currentSubType = i))
                },
                u = function() {
                    var i = n.mainTypeTabs.find(n => n.active),
                        t, r;
                    i && (i.name == "正畸词条-牙型与骨型" ? t = {
                        itemContent: ""
                    } : (r = n.currentSubType.items.length, t = {
                        itemName: "",
                        itemCode: "",
                        itemContent: "",
                        order: r
                    }), n.currentSubType.items.push(t))
                },
                f = function(t, i) {
                    $.trim(t.itemContent) == "" ? n.currentSubType.items.splice(i, 1) : e.confirm("提示", "确定要删除此内容？").then(function() {
                        n.currentSubType.items.splice(i, 1)
                    })
                },
                s = function() {
                    n.currentSubTypeCache = angular.copy(n.currentSubType);
                    n.isEdit = !0
                },
                h = function() {
                    var i = !1,
                        t;
                    if (angular.forEach(n.currentSubTypeItems, function(n) {
                            $.trim(n.itemContent) == "" && (i = !0)
                        }), i) {
                        e.warn("提示", "诊断配置项目内容不能为空");
                        return
                    }
                    t = n.mainTypeTabs.find(n => n.active);
                    t && (t.name == "正畸词条-牙型与骨型" ? n.saveDiagnosticItemContent(n.currentSubType.items) : n.saveOrthdonticItemContent(n.currentSubType.subTypeId))
                },
                c = function() {
                    n.currentSubType = angular.copy(n.currentSubTypeCache);
                    n.isEdit = !1
                },
                l = function(n) {
                    var i, t;
                    if (n.length === 0) return 0;
                    for (i = n[0].subTypeOrder, t = 0; t < n.length; t++) i < n[t].subTypeOrder && (i = n[t].subTypeOrder);
                    return i + 1
                },
                a = function() {
                    var t = l(n.currentMainTypeConfig.subTypes),
                        i = o.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<orthdontic-template-itemsetting-category-view><\/orthdontic-template-itemsetting-category-view>",
                            controller: "OrthdonticTemplateItemsettingCategoryCtrl",
                            size: "sm",
                            resolve: {
                                host: function() {
                                    return {
                                        id: 0,
                                        mainType: n.currentMainTypeConfig.mainType,
                                        subType: "",
                                        order: t
                                    }
                                }
                            }
                        });
                    i.result.then(function(t) {
                        var i = {
                                subType: t.subType,
                                subTypeId: t.id,
                                subTypeOrder: t.order,
                                items: []
                            },
                            r = !1;
                        angular.forEach(n.diagnosticConfigData, function(i) {
                            i.mainType == t.mainType && (n.currentMainTypeConfig = i, r = !0)
                        });
                        n.diagnosticConfigData.length === 0 && (n.currentMainTypeConfig.subTypes = [], n.currentMainTypeConfig.mainType = t.mainType);
                        n.currentMainTypeConfig.subTypes.forEach(n => n.selected = !1);
                        i.selected = !0;
                        n.currentSubType = i;
                        n.currentMainTypeConfig.subTypes.push(i);
                        r || n.diagnosticConfigData.push(n.currentMainTypeConfig)
                    })
                },
                v = function(t) {
                    var i = n.currentMainTypeConfig.mainType,
                        r = o.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<orthdontic-template-itemsetting-category-view><\/orthdontic-template-itemsetting-category-view>",
                            controller: "OrthdonticTemplateItemsettingCategoryCtrl",
                            size: "sm",
                            resolve: {
                                host: function() {
                                    return {
                                        id: t.subTypeId,
                                        mainType: i,
                                        subType: t.subType,
                                        order: t.subTypeOrder
                                    }
                                }
                            }
                        });
                    r.result.then(function(t) {
                        angular.forEach(n.currentMainTypeConfig.subTypes, function(n) {
                            n.subTypeId == t.id && (n.subType = t.subType)
                        })
                    })
                },
                y = function(t, i) {
                    if (t.items.length > 0) {
                        e.warn("提示", "请先清空类目中的内容");
                        return
                    }
                    e.confirm("提示", "确定要删除此类目？").then(function() {
                        n.deleteSubTypeItem(t.subTypeId, i)
                    })
                },
                p = function() {
                    var t = "正畸词条-牙型与骨型";
                    n.initDiagnosticConfig().then(function() {
                        var i = n.diagnosticConfigData.find(n => n.mainType == t),
                            r;
                        i && i.subTypes.length > 0 && (r = i.subTypes[0], r.selected = !0, n.currentSubType = r);
                        n.currentMainTypeConfig = i
                    });
                    n.mainTypeTabs = [{
                        name: "正畸词条-牙型与骨型",
                        active: !0
                    }, {
                        name: "正畸词条-主诉"
                    }, {
                        name: "正畸词条-问题"
                    }, {
                        name: "正畸词条-目标",
                        showName: "矫治目标"
                    }];
                    n.isShowSubType = !0
                };
            (function() {
                n.changeMainTypeItem = i;
                n.changeSubType = r;
                n.createDiagnosticItem = u;
                n.deleteDiagnosticItem = f;
                n.editDiagnosticItem = s;
                n.saveDiagnosticItem = h;
                n.cancelDiagnosticItem = c;
                n.creteSubType = a;
                n.editSubType = v;
                n.deleteSubType = y;
                p()
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanPlanChargeChoiceView", ["$log", "$timeout", "$window", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-plan-charge-choice-view.html",
        link: function(n, r) {
            var f = null,
                e = function() {
                    var t = this;
                    $(r).find("#itemGrid table tbody tr").each(function(i, r) {
                        var u = t.dataItem(r),
                            f = _.find(n.giftPlanList, function(n) {
                                return n.itemName == u.itemName ? !0 : !1
                            });
                        f ? $("td.cell-command", r).find('button[data-action="add"]').remove() : $("td.cell-command", r).find('button[data-action="remove"]').remove()
                    })
                },
                o = function() {
                    var u = Ares.kendoGridUtil(i, n),
                        t;
                    n.chargeCatagoryList && (t = r.find("#itemGrid"), t.html(""), f = t.kendoGrid({
                        dataSource: {
                            data: n.chargeItemListFilteResult
                        },
                        height: 500,
                        sortable: !0,
                        selectable: "single",
                        dataBound: e,
                        columns: [{
                            field: "itemName",
                            title: "名称",
                            width: "150px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "procedureCode",
                            title: "编码",
                            width: "80px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "unit",
                            title: "单位",
                            width: "50px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "price",
                            title: "单价",
                            width: "50px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            template: u.commandTemplate,
                            title: "",
                            width: "60px",
                            attributes: {
                                "class": "cell-command"
                            }
                        }]
                    }).data("kendoGrid"))
                },
                s = [{
                    text: "添加处置",
                    action: "add",
                    icon: "glyphicon-plus"
                }, {
                    text: "取消",
                    action: "remove",
                    icon: "glyphicon-minus"
                }],
                h = function(t) {
                    return _.find(n.chargeItemList, function(n) {
                        return n.id == t
                    })
                },
                c = function(t, i, r) {
                    n.$apply(function() {
                        var t = h(r),
                            u = {
                                id: t.id,
                                itemName: t.itemName,
                                itemId: t.id,
                                price: t.price,
                                count: 1
                            };
                        switch (i) {
                            case "add":
                                n.add(u);
                                break;
                            case "remove":
                                n.remove(u)
                        }
                    })
                },
                u = function() {
                    f ? n.chargeItemListFilteResult ? f.dataSource.data(n.chargeItemListFilteResult) : f.dataSource.data([]) : o()
                },
                l = function(t) {
                    var i = _.find(n.giftPlanList, function(n) {
                        return n.itemName == t.itemName ? !0 : !1
                    });
                    i ? alert("a") : (n.giftPlanList.push(t), u())
                },
                a = function(t) {
                    var i = _.findIndex(n.giftPlanList, function(n) {
                        return n.itemName == t.itemName ? !0 : !1
                    });
                    i > -1 && (n.giftPlanList.splice(i, 1), u())
                },
                v = function() {
                    n.chargeItemsFilter = "";
                    n.resetChargeItemList(null, n.defaultSupCategoryId)
                },
                y = function() {
                    n.chargeItemsFilter = "";
                    n.resetChargeItemList(n.defaultCategoryId)
                },
                p = function() {
                    n.chargeItemListFilteResult = n.chargeItemsFilter ? n.chargeItemList.filter(function(t) {
                        return t.itemName.indexOf(n.chargeItemsFilter) > -1 || t.pinyin && t.pinyin.indexOf(n.chargeItemsFilter) > -1
                    }) : angular.copy(n.chargeItemList);
                    u()
                };
            (function() {
                n.commands = s;
                n.onCommandClick = c;
                n.add = l;
                n.remove = a;
                n.onHandleTypeSelected = y;
                n.onHandleSupCategorySelect = v;
                n.chargeItemsFilter = "";
                n.filteChargeItemByFilter = p;
                n.$watch("chargeItemList", function() {
                    n.chargeItemListFilteResult = angular.copy(n.chargeItemList);
                    u()
                });
                n.$watch("selectHandleItem", function() {
                    n.selectHandleItem == !0 && (n.selectHandleCatagory = 0, n.chargeCatagoryList.length > 0 && (n.selectHandleCatagory = n.chargeCatagoryList[0].id, u()))
                })
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanPlanDialogView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-plan-dialog-view.html",
        link: function(n, i) {
            var u = function(t) {
                    var i = {
                            code: t.code,
                            orthoStepId: t.id,
                            name: t.name
                        },
                        r = _.find(n.treatmentPlan.steps, function(n) {
                            return n.orthoStepId == t.id
                        });
                    r || n.treatmentPlan.steps.push(i)
                },
                f = function(t) {
                    n.treatmentPlan.steps.splice(t, 1)
                },
                r, e = function() {
                    r = Ares.validateForm(i.find("#orthoPlanForm"), {
                        code: {
                            required: !0,
                            maxlength: 30
                        },
                        name: {
                            required: !0,
                            maxlength: 200
                        }
                    }, {
                        code: {
                            required: "请输入方案代码",
                            maxlength: "方案代码不能超过30个字符"
                        },
                        name: {
                            required: "请输入方案名称",
                            maxlength: "方案名称不能大于200个字！",
                            valName: "该名称已被使用！"
                        }
                    })
                },
                o = function() {
                    i.find("#orthoPlanForm").valid() && n.savePlan()
                };
            (function() {
                e();
                n.validAndSave = o;
                n.selectText = u;
                n.deleteSelectedText = f;
                n.$watch("treatmentPlan", function() {
                    r && Ares.clearError(i.find("#orthoPlanForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanPlanView", ["$log", "$timeout", "$window", "dataDicSvc", "orthoSvc", "officeUtil", "aresDialog", "$modal", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-plan-view.html",
        controller: "OrthdonticSettingPlanPlanCtrl",
        link: function(n, t) {
            var f = Ares.kendoGridUtil(i, n),
                r = null,
                s = function() {
                    var n = this;
                    $(t).find("#orthoPlans table tbody tr").each(function(t, i) {
                        var r = n.dataItem(i);
                        r.isInactive ? $(this).find("td .btn-group").find('button[data-action="change"]').text("启用") : $(this).find("td .btn-group").find('button[data-action="change"]').text("禁用")
                    })
                },
                u = function() {
                    var i, u;
                    n.orthoPlans && (i = [{
                        field: "code",
                        title: "方案代码",
                        width: "140px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "name",
                        title: "方案名称",
                        width: "300px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "isInactive",
                        title: "是否启用",
                        width: "100px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        },
                        template: function(n) {
                            return n.isInactive ? "否" : "是"
                        }
                    }, {
                        field: "price",
                        title: "费用",
                        width: "100px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, ], i.push({
                        template: f.commandTemplate,
                        title: "",
                        width: "100px"
                    }), u = $(t).find("#orthoPlans"), r = u.kendoGrid({
                        dataSource: n.orthoPlans,
                        dataBound: s,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        columns: i
                    }).data("kendoGrid"))
                },
                h = function() {
                    r ? r.dataSource.data(n.orthoPlans) : n.initList()
                },
                c = [{
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "禁用",
                    action: "change"
                }, ],
                l = function(t) {
                    return _.find(n.orthoPlans, function(n) {
                        return n.id == t
                    })
                },
                a = function(t, i, r) {
                    var u = l(r);
                    switch (i) {
                        case "update":
                            n.editPlan(u);
                            break;
                        case "change":
                            n.changePlan(u);
                            h()
                    }
                },
                v = function() {
                    var t = o.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-setting-plan-plan-dialog-view><\/orthdontic-setting-plan-plan-dialog-view>",
                        controller: "OrthdinticSettingPlanPlanDialogCtrl",
                        size: "md",
                        resolve: {
                            host: function() {
                                return {
                                    planId: 0,
                                    orthoAllPlans: n.orthoAllPlans
                                }
                            }
                        }
                    });
                    t.result.then(function() {
                        n.browserPlans()
                    })
                },
                y = function(t) {
                    var i = o.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-setting-plan-plan-dialog-view><\/orthdontic-setting-plan-plan-dialog-view>",
                        controller: "OrthdinticSettingPlanPlanDialogCtrl",
                        size: "md",
                        resolve: {
                            host: function() {
                                return {
                                    planId: t.id,
                                    orthoAllPlans: n.orthoAllPlans
                                }
                            }
                        }
                    });
                    i.result.then(function() {
                        n.browserPlans()
                    })
                },
                p = function(t) {
                    var i = "启用";
                    t.isInactive || (i = "禁用");
                    e.confirm("提示", "确定要" + i + "此方案？").then(function() {
                        n.changeSelectPlan(t)
                    })
                };
            (function() {
                n.$watch("orthoPlans", function(n) {
                    n && u()
                });
                n.$watch("showIsEableOrAll", function(t) {
                    n.orthoAllPlans && (n.orthoPlans = t ? n.orthoAllPlans : n.orthoIsInactivePlans)
                });
                n.initList = u;
                n.onCommandClick = a;
                n.commands = c;
                n.changePlan = p;
                n.createPlan = v;
                n.editPlan = y
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanStepDialogView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-step-dialog-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#orthoStepForm"), {
                        name: {
                            required: !0,
                            maxlength: 200,
                            valName: !0
                        },
                        code: {
                            required: !0,
                            maxlength: 30,
                            valCode: !0
                        }
                    }, {
                        name: {
                            required: "请输入正畸步骤名称",
                            maxlength: "步骤名称不能大于200个字！",
                            valName: "该名称已被使用！"
                        },
                        code: {
                            required: "请输入步骤编码",
                            maxlength: "步骤编码不能超过30个字符",
                            valCode: "编码已被使用！"
                        }
                    })
                },
                f = function() {
                    i.find("#orthoStepForm").valid() && n.saveStep()
                };
            (function() {
                u();
                n.validAndSave = f;
                n.$watch("orthoStep", function() {
                    r && Ares.clearError(i.find("#orthoStepForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanStepView", ["$log", "$timeout", "$window", "dataDicSvc", "orthoSvc", "officeUtil", function(n, t, i, r, u) {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-step-view.html",
        controller: "OrthdonticSettingPlanStepCtrl",
        link: function(n, t) {
            var o = Ares.kendoGridUtil(i, n),
                f = null,
                s = function() {
                    var i, r;
                    n.orthoSteps && (i = [{
                        field: "code",
                        title: "步骤编码",
                        width: "140px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "name",
                        title: "名称",
                        width: "300px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "pinyin",
                        title: "拼音",
                        width: "100px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, ], i.push({
                        template: o.commandTemplate,
                        title: "",
                        width: "100px"
                    }), r = $(t).find("#orthoSteps"), f = r.kendoGrid({
                        dataSource: n.orthoSteps,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        columns: i,
                        excel: {
                            fileName: "正畸步骤.xlsx"
                        }
                    }).data("kendoGrid"))
                },
                e = function() {
                    f ? f.dataSource.data(n.orthoSteps) : n.initList()
                },
                h = [{
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "删除",
                    action: "delete",
                    icon: "glyphicon-remove"
                }, ],
                c = function(t) {
                    return _.find(n.orthoSteps, function(n) {
                        return n.id == t
                    })
                },
                l = function(t, i, r) {
                    var u = c(r);
                    switch (i) {
                        case "update":
                            n.editStep(u);
                            break;
                        case "delete":
                            n.deleteStep(u);
                            e()
                    }
                },
                a = function() {
                    f && f.saveAsExcel()
                },
                v = function() {
                    u.listAllSteps().success(function(t) {
                        var r, i, u;
                        if (n.searchString == "") {
                            n.orthoSteps = t;
                            e();
                            return
                        }
                        for (r = [], i = 0; i < t.length; i++) u = t[i], u.name.toLowerCase().indexOf(n.searchString.toLowerCase()) > -1 && r.push(u);
                        n.orthoSteps = r;
                        e()
                    })
                };
            (function() {
                r.orthoStepDic.load();
                n.initList = s;
                n.$watch("orthoSteps", function() {
                    e()
                });
                n.$watch("searchString", function() {
                    v()
                });
                n.commands = h;
                n.onCommandClick = l;
                n.exportItemExcel = a
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingPlanView", ["$log", "appNav", "$state", "$stateParams", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-setting-plan-view.html",
        link: function(n) {
            var i = function(n) {
                    t.switchState(n, {})
                },
                r = function(i) {
                    t.switchState(i, {});
                    i === n.orthoAgreementMenu ? (n.diagnosticConfigActive = !1, n.agreementActive = !0, n.stepActive = !1, n.planActive = !1) : i === n.orthoStepMenu ? (n.diagnosticConfigActive = !1, n.agreementActive = !1, n.stepActive = !0, n.planActive = !1) : i === n.orthoPlanMenu ? (n.diagnosticConfigActive = !1, n.agreementActive = !1, n.stepActive = !1, n.planActive = !0) : i === n.orthoDiagnosticConfigMenu && (n.diagnosticConfigActive = !0, n.agreementActive = !1, n.stepActive = !1, n.planActive = !1)
                };
            (function() {
                n.switchPage = r;
                n.orthoAgreementMenu = "orthdontic.settings.plan.orthagreement";
                n.orthoStepMenu = "orthdontic.settings.plan.step";
                n.orthoPlanMenu = "orthdontic.settings.plan.plan";
                n.orthoDiagnosticConfigMenu = "orthdontic.settings.plan.diagnosticConfig";
                n.diagnosticConfigActive = !0;
                n.agreementActive = !1;
                n.stepActive = !1;
                n.planActive = !1;
                i(n.orthoDiagnosticConfigMenu)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingProcessBasicConfigView", [function() {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-process-basic-config-view.html",
        controller: "OrthdonticSettingProcessBasicConfigCtrl",
        link: function(n) {
            var t = function() {
                    n.configCache = angular.copy(n.orthoProcessSetting);
                    n.isEdit = !0
                },
                i = function() {
                    n.orthoProcessSetting = angular.copy(n.configCache);
                    n.isEdit = !1
                };
            (function() {
                n.editConfig = t;
                n.cancel = i
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingProcessTemplateConfigView", ["$log", "$q", "$timeout", "$window", "$modal", "patientSvc", "aresDialog", "enums", "loginContext", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-process-template-config-view.html",
        controller: "OrthdonticSettingProcessTemplateConfigCtrl",
        link: function(i, r) {
            var h = function(n, t, r) {
                    var e = {
                            type: t,
                            itemData: n
                        },
                        f;
                    r && (e.isEmrCustomTemplateEnabled = i.isEmrCustomTemplateEnabled);
                    switch (t) {
                        case 1:
                            f = i.templateTreeControl.getParent(n);
                            break;
                        case 2:
                            f = n;
                            break;
                        case 3:
                            f = n;
                            break;
                        default:
                            breka
                    }
                    return e.parentNode = f, u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-template-config-create-item-view><\/orthdontic-template-config-create-item-view>",
                        controller: "OrthdonticTemplateConfigCreateItemCtrl",
                        windowClass: r ? "emrtemplate-browser-create-item" : "emrtemplate-browser-create-directory",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return e
                            }
                        }
                    })
                },
                c = function(t, r) {
                    var u = h(t, r);
                    u.result.then(function(r) {
                        t.id === 0 && t.itemName === "我的模板" && (r.ownerId = s.userId);
                        t.ownerId && (r.ownerId = s.userId);
                        r.diseaseType = o.DiseaseType.Orthodontic;
                        f.createDiseaseItem(r).success(function(n) {
                            i.templateTreeControl.addBranch(n)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                l = function() {
                    c({
                        id: 0
                    }, 2)
                },
                a = function(t, i) {
                    var r = h(t, i);
                    r.result.then(function(i) {
                        f.updateDiseaseItem(i).success(function() {
                            t.itemName = i.itemName
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                v = function(t) {
                    if (i.deleteDiseaseItem = angular.copy(t), t.childrenItems && t.childrenItems.length > 0) {
                        e.info("提示", "该模板目录下还有可用的模板，不能删除！");
                        return
                    }
                    e.confirm("提示", "确认删除目录" + i.deleteDiseaseItem.itemName).then(function() {
                        f.deleteDiseaseItem(i.deleteDiseaseItem.id).success(function() {
                            i.templateTreeControl.deleteBranch(i.deleteDiseaseItem)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                y = function(t, r) {
                    var u = h(t, r, 1);
                    u.result.then(function(r) {
                        t.ownerId && (r.userId = s.userId);
                        r.templateType = i.templateType;
                        f.createEMRTemplate(r).success(function(n) {
                            i.templateTreeControl.addLeaf(n)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                p = function(t) {
                    if (i.deleteEMRTemplate = angular.copy(t), t.childrenItems && t.childrenItems.length > 0) {
                        e.info("提示", "该模板目录下还有可用的模板，不能删除！");
                        return
                    }
                    e.confirm("提示", "确认删除病历模板" + i.deleteEMRTemplate.templateName).then(function() {
                        f.deleteEMRTemplate(i.deleteEMRTemplate.id).success(function() {
                            i.templateTreeControl.deleteLeaf(i.deleteEMRTemplate);
                            i.currentEmrTemplate = {};
                            i.selectedNoe = null
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                w = function(n) {
                    n.spriteCssClass == "image" ? p(n) : v(n)
                },
                b = function(n) {
                    i.diseaseItemName = i.templateTreeControl.getBranchBreadcrumbById(n)
                },
                k = function(n) {
                    if (n && n.spriteCssClass === "image") {
                        if (i.isEditEmrTemplate) {
                            i.selectedNode = angular.copy(i.currentEmrTemplate);
                            e.warn("提示", "当前编辑的模板未保存，请保存或取消后再进行其他操作");
                            return
                        }
                        i.currentEmrTemplate = angular.copy(n);
                        i.showSaveBtn = !0;
                        i.selectedNoe = angular.copy(n);
                        var t = n.diseaseId;
                        b(t)
                    } else i.currentEmrTemplate = {
                        itemName: n.itemName
                    }, i.showSaveBtn = !1;
                    event.stopPropagation()
                },
                d = function(n, t) {
                    switch (t) {
                        case 1:
                            a(n, 1);
                            break;
                        case 2:
                            c(n, 2);
                            break;
                        case 3:
                            y(n, 3);
                            break;
                        case 4:
                            w(n)
                    }
                },
                g = function() {
                    $.validator.addMethod("noSameNameNodeWithScope", function(n, t, r) {
                        var u = r.currentEmrTemplate.templateName === r.savedEmrTemplate.templateName,
                            f = !i.templateTreeControl.checkDuplicateNameSibling(i.currentEmrTemplate);
                        return this.optional(t) || u || f
                    }, "已存在同名的同级目录或模板");
                    $.validator.addMethod("notEqualToMyTemplate", function(n, t) {
                        return this.optional(t) || n !== "我的模板"
                    }, "名称不能为“我的模板”");
                    Ares.validateForm(r.find("#emrTemplateForm"), {
                        templateName: {
                            required: !0,
                            noSameNameNodeWithScope: i
                        }
                    }, {
                        templateName: {
                            required: "请输入模板名称"
                        }
                    })
                },
                nt = function() {
                    r.find("#emrTemplateForm").valid() && i.saveEmrTemplate()
                };
            (function() {
                i.templateType = o.TemplateType.Orthodontic;
                i.showSelected = k;
                i.templateOperate = d;
                i.addDiseaseItem = l;
                i.diseaseItemName = [];
                i.saveEmrTemplateWithValidation = nt;
                t.all([i.initEHRParentEnabled()]).then(function() {
                    i.browserEMRTemplateSetting(i.templateType)
                });
                g();
                i.$watch("isEditEmrTemplate", function() {
                    var n = r.find("#emrTemplateForm");
                    n.data("validator") && Ares.clearError(n)
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingProcessTemplateItemConfigView", ["$log", "$q", "$timeout", "$window", "$modal", "patientSvc", "aresDialog", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        templateUrl: "/app/orthdontic/views/orthdontic-setting-process-template-item-config-view.html",
        controller: "OrthdonticSettingProcessTemplateItemConfigCtrl",
        link: function(n) {
            var t = function() {
                    return n.isEdit ? (e.warn("提示", "请先保存编辑中的内容"), !0) : !1
                },
                r = function(r, u) {
                    var f = t();
                    f || (n.mainType = r, n.subTypesMap = {
                        mainType: r,
                        subTypes: []
                    }, n.showSubTypeIndex = u, angular.forEach(n.orthdonticTemplateItemSettingData, function(t) {
                        t.mainType == r && (n.subTypesMap = t)
                    }), i(n.subTypesMap.subTypes[0], 0), n.isShowSubType = 0)
                },
                i = function(i, r) {
                    var u = t();
                    u || (n.subItems = i, n.showItemIndex = r, n.isEdit = !1)
                },
                f = function(n) {
                    var i, t;
                    if (n.length === 0) return 0;
                    for (i = n[0].subTypeOrder, t = 0; t < n.length; t++) i < n[t].subTypeOrder && (i = n[t].subTypeOrder);
                    return i + 1
                },
                o = function() {
                    var t = f(n.subTypesMap.subTypes),
                        i = u.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<orthdontic-template-itemsetting-category-view><\/orthdontic-template-itemsetting-category-view>",
                            controller: "OrthdonticTemplateItemsettingCategoryCtrl",
                            size: "sm",
                            resolve: {
                                host: function() {
                                    return {
                                        id: 0,
                                        mainType: n.mainType,
                                        subType: "",
                                        order: t
                                    }
                                }
                            }
                        });
                    i.result.then(function(t) {
                        var r = {
                                subType: t.subType,
                                subTypeId: t.id,
                                subTypeOrder: t.order,
                                items: []
                            },
                            i = !1;
                        angular.forEach(n.orthdonticTemplateItemSettingData, function(r) {
                            r.mainType == t.mainType && (n.subTypesMap = r, i = !0)
                        });
                        n.orthdonticTemplateItemSettingData.length === 0 && (n.subTypesMap.subTypes = [], n.subTypesMap.mainType = t.mainType);
                        n.subTypesMap.subTypes.length === 0 && (n.showItemIndex = -1);
                        n.subTypesMap.subTypes.push(r);
                        i || n.orthdonticTemplateItemSettingData.push(n.subTypesMap)
                    })
                },
                s = function(t, i) {
                    var r = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<orthdontic-template-itemsetting-category-view><\/orthdontic-template-itemsetting-category-view>",
                        controller: "OrthdonticTemplateItemsettingCategoryCtrl",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    id: t.subTypeId,
                                    mainType: i,
                                    subType: t.subType,
                                    order: t.subTypeOrder
                                }
                            }
                        }
                    });
                    r.result.then(function(t) {
                        angular.forEach(n.subTypesMap.subTypes, function(n) {
                            n.subTypeId == t.id && (n.subType = t.subType)
                        })
                    })
                },
                h = function(t, i) {
                    if (t.items.length > 0) {
                        e.warn("提示", "请先清空类目中的内容");
                        return
                    }
                    e.confirm("提示", "确定要删除此类目？").then(function() {
                        n.deleteSubTypeItem(t.subTypeId, i)
                    })
                },
                c = function() {
                    var t = n.subItems.items.length,
                        i = {
                            itemName: "",
                            itemCode: "",
                            itemContent: "",
                            order: t
                        };
                    n.subItems.items.push(i)
                },
                l = function(t, i) {
                    $.trim(t.itemContent) == "" ? n.subItems.items.splice(i, 1) : e.confirm("提示", "确定要删除此内容？").then(function() {
                        n.subItems.items.splice(i, 1)
                    })
                },
                a = function() {
                    if (n.subItems)
                        if (n.itemsCache = angular.copy(n.subItems.items), n.subItems.subTypeId > 0) n.isEdit = !0;
                        else {
                            e.warn("提示", "请选择词条类目");
                            return
                        }
                    else e.warn("提示", "请选择词条类目")
                },
                v = function() {
                    var t = !1;
                    if (angular.forEach(n.subItems.items, function(n) {
                            $.trim(n.itemContent) == "" && (t = !0)
                        }), t) {
                        e.warn("提示", "词条内容不能为空");
                        return
                    }
                    n.saveOrthdonticItemContent(n.subItems.subTypeId)
                },
                y = function() {
                    n.subItems.items = angular.copy(n.itemsCache);
                    n.isEdit = !1
                };
            (function() {
                n.changeMainTypeItem = r;
                n.changeSubType = i;
                n.creteSubType = o;
                n.editSubType = s;
                n.deleteSubType = h;
                n.createOrthdonticItem = c;
                n.deleteOrthdonticItem = l;
                n.editOrthdonticItem = a;
                n.saveOrthdonticItem = v;
                n.cancelOrthdonticItem = y
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingProcessView", ["$log", "appNav", "$state", "$stateParams", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-setting-process-view.html",
        link: function(n) {
            var i = function(n) {
                    t.switchState(n, {})
                },
                r = function(i) {
                    t.switchState(i, {});
                    i === n.orthoProcessBasicConfigMenu ? (n.basicConfigActive = !0, n.templateConfigActive = !1, n.templateItemConfigActive = !1) : i === n.orthoProcessTemplateConfigMenu ? (n.basicConfigActive = !1, n.templateConfigActive = !0, n.templateItemConfigActive = !1) : i === n.orthoProcessTemplateItemConfigMenu && (n.basicConfigActive = !1, n.templateConfigActive = !1, n.templateItemConfigActive = !0)
                };
            (function() {
                n.switchPage = r;
                n.orthoProcessBasicConfigMenu = "orthdontic.settings.process.basicConfig";
                n.orthoProcessTemplateConfigMenu = "orthdontic.settings.process.templateConfig";
                n.orthoProcessTemplateItemConfigMenu = "orthdontic.settings.process.templateItemConfig";
                n.basicConfigActive = !0;
                n.templateItemConfigActive = !1;
                i(n.orthoProcessBasicConfigMenu)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticSettingView", [function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-setting-view.html",
        scope: {},
        link: function() {
            (function() {})()
        }
    }
}]);
orthdonticModule.directive("orthdonticTemplateConfigCreateItemView", ["$log", function() {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-template-config-create-item-view.html",
        link: function(n, t) {
            $.validator.addMethod("noSameNameNode", function(t, i, r) {
                return this.optional(i) || !_.some(r.childrenItems, function(i) {
                    return n.newDiseaseItem ? t === i.itemName && n.newDiseaseItem.id !== i.id : t === i.itemName
                })
            }, "已存在同名的同级目录或模板");
            $.validator.addMethod("notEqualToMyTemplate", function(n, t) {
                return this.optional(t) || n !== "我的模板"
            }, "名称不能为“我的模板”");
            var i, r, u = function() {
                    i = Ares.validateForm(t.find("#addDiseaseItemForm"), {
                        itemName: {
                            required: !0,
                            noSameNameNode: n.parentNode,
                            notEqualToMyTemplate: !0
                        }
                    }, {
                        itemName: {
                            required: "请输入目录名称"
                        }
                    });
                    r = Ares.validateForm(t.find("#emrTemplateAddForm"), {
                        templateName: {
                            required: !0,
                            noSameNameNode: n.parentNode,
                            notEqualToMyTemplate: !0
                        }
                    }, {
                        templateName: {
                            required: "请输入模板名称"
                        }
                    })
                },
                f = function() {
                    switch (n.showType) {
                        case 1:
                            t.find("#addDiseaseItemForm").valid() && n.saveDiseaseItem();
                            break;
                        case 2:
                            t.find("#addDiseaseItemForm").valid() && n.saveDiseaseItem();
                            break;
                        case 3:
                            t.find("#emrTemplateAddForm").valid() && n.saveEmrTemplate()
                    }
                };
            (function() {
                u();
                n.save = f;
                n.$watch("newDiseaseItem", function() {
                    i && Ares.clearError(t.find("#addDiseaseItemForm"));
                    r && Ares.clearError(t.find("#emrTemplateAddForm"))
                })
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticTemplateConfigDirectoryMoveView", ["$log", "$timeout", "aresDialog", "loginContext", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-template-config-directory-move-view.html",
        link: function(n) {
            var t = "",
                f = null,
                u, e = function(i) {
                    u = i;
                    t = i.id;
                    n.clickedName = i.itemName;
                    i && (i.departmentName === "我的模板" || i.itemName === "我的模板") && (f = r.userId)
                },
                o = function() {
                    if (u.id !== n.currentEmrTemplate.diseaseId && _.some(u.childrenItems, function(t) {
                            return t.itemName === n.currentEmrTemplate.itemName
                        })) {
                        i.info("提示", "该目录下已有同名的目录或模板，无法移动！");
                        return
                    }
                    var r = {
                        id: n.currentEmrTemplate.id,
                        diseaseId: t,
                        templateType: n.templateType,
                        userId: f
                    };
                    if (!(t === 0 || t)) {
                        i.info("提示", "请选择目录！");
                        return
                    }
                    n.moveTemplate(r)
                };
            (function() {
                n.getContent = e;
                n.sureMoveTemplate = o
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticTemplateItemsettingCategoryView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/orthdontic/views/orthdontic-template-itemsetting-category-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#ruleSettingForm"), {
                        subType: {
                            required: !0,
                            maxlength: 30
                        }
                    }, {
                        subType: {
                            required: "请输入类目名称",
                            maxlength: "类目名称不能超过30个字符"
                        }
                    })
                },
                f = function() {
                    i.find("#ruleSettingForm").valid() && n.saveEmrtemplageItemSetting()
                };
            (function() {
                u();
                n.validAndSave = f;
                n.$watch("mainType", function() {
                    r && Ares.clearError(i.find("#ruleSettingForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
orthdonticModule.directive("orthdonticXrayAnalysisView", ["$log", "$timeout", "$state", "$stateParams", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        controller: "OrthdonticXrayAnalysisCtrl",
        templateUrl: "/app/orthdontic/views/orthdontic-xray-analysis-view.html",
        link: function(n) {
            var i = function() {
                n.category || (n.category = n.categories[0]);
                n.constructCurrentXrayData()
            };
            (function() {
                n.$watch("categories", function() {
                    n.categories && t(function() {
                        i()
                    })
                })
            })()
        }
    }
}]);
clinicalModule.directive("orthdonticXrayPrintView", ["$log", "$timeout", "$q", "$location", "enums", "patientSvc", "generalExamSvc", "officeSvc", "dataDicSvc", "loginContext", "aresDialog", "orthoSvc", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/orthdontic/views/orthdontic-xray-print-view.html",
        scope: {
            patientId: "@",
            categoryId: "@"
        },
        link: function(n, u) {
            function it() {
                u.find(".full-width").each(function() {
                    $(this).css("margin-top", ($(this).parent().height() - $(this).height()) / 2)
                })
            }
            var o = !1,
                h = !1,
                c = !1,
                a = 0,
                v = 10,
                y = 310 / 150,
                p = 126 / 150,
                w = function() {
                    var t = i.defer();
                    return l.getPatientXRayFields(n.patientId).success(function(i) {
                        n.patientExamResults = i;
                        s.orthoXRayFieldDic.load().then(function(i) {
                            if (i) {
                                var r = angular.copy(i);
                                n.category = _.find(r, function(t) {
                                    return t.id === n.categoryId
                                });
                                rt();
                                h = !0
                            }
                            t.resolve(!0)
                        })
                    }), t.promise
                },
                b = function() {
                    var t = i.defer();
                    return f.getPatient(n.patientId).success(function(i) {
                        n.patient = i;
                        c = !0;
                        t.resolve(!0)
                    }), t.promise
                },
                e = function(n) {
                    return [{
                        id: 0,
                        position: 0,
                        title: "上传全口曲面断层片",
                        inputId: "imageUploadPanel" + n + "0",
                        orthoImageType: n === 0 ? 0 : 1,
                        seqNum: n
                    }, {
                        id: 0,
                        position: 1,
                        title: "上传头颅侧位片",
                        inputId: "imageUploadPanel" + n + "1",
                        orthoImageType: n === 0 ? 0 : 1,
                        seqNum: n
                    }]
                },
                k = function() {
                    var t = i.defer();
                    return l.getPatientXrayImages(n.patientId).success(function(i) {
                        var u, r;
                        if (n.xrayImages = [], n.examImages = [], _.each(i, function(t) {
                                var r, i;
                                t.image && n.examImages.push(t.image);
                                r = typeof t.seqNum == "number" ? t.seqNum : t.imageType;
                                n.xrayImages[r] = n.xrayImages[r] || e(r);
                                i = t.image;
                                i.position = t.position;
                                i.imageDateString = g(t.imageDate);
                                i.inputId = "imageUploadPanel" + r + i.position;
                                i.orthoImageType = r === 0 ? 0 : 1;
                                d(i);
                                n.xrayImages[r][i.position] = i
                            }), n.xrayImages.length === 0) n.xrayImages.push(e(0));
                        else
                            for (u = _.max(Object.keys(n.xrayImages)), r = u; r > 1; --r) n.xrayImages[r - 1] || (n.xrayImages[r - 1] = e(r - 1));
                        o = !0;
                        t.resolve(!0)
                    }), t.promise
                },
                d = function(n) {
                    n.position === 0 ? n.isWidthLarger = n.width / n.height >= y : n.position === 1 && (n.isWidthLarger = n.width / n.height >= p)
                },
                g = function(n) {
                    return n ? moment(n).format("YYYY-MM-DD") : null
                },
                nt = function(n) {
                    t(function() {
                        c && o && h ? tt(n) : (a++, a > v ? n && n(!1) : n(!0))
                    }, 1e3)
                },
                tt = function(i) {
                    var r = u.find("#imgContainer");
                    angular.forEach(n.examImages, function(n) {
                        var t = '<img style="width:50px;" src="' + n.thumbnailUrl + '" />';
                        r.append(t)
                    });
                    r.waitForImages(function() {
                        t(function() {
                            it();
                            window.print();
                            i && i(!0)
                        }, 100)
                    })
                },
                rt = function() {
                    var t = {},
                        i, r;
                    _.each(n.category.orthoFields, function(n) {
                        t[n.id] = n
                    });
                    i = _.find(n.patientExamResults, function(t) {
                        return t.categoryId === n.category.id
                    });
                    i && (r = i.data, _.each(r, function(n) {
                        var i = n.seqNum,
                            r = n.fields;
                        _.each(r, function(n) {
                            t[n.fieldId].xrayValues = t[n.fieldId].xrayValues || [];
                            t[n.fieldId].xrayValues[i] = n.value
                        })
                    }));
                    n.currentXrayData = t
                },
                ut = function() {
                    var t = r.search();
                    n.param = t;
                    n.patientId = t.patientId;
                    n.categoryId = parseInt(t.categoryId)
                };
            (function() {
                ut();
                w().then(function() {
                    k().then(function() {
                        b();
                        window.printEx = nt
                    })
                })
            })()
        }
    }
}]);